最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Error in Cygwin seems to mismatch the description - Stack Overflow

programmeradmin0浏览0评论

The error says:

error: expected ',' or '...' before '(' token
 int exec_wait(const std::string& path, std::string& stdout, ...)
                                                     ^

Anyone has any clues why it's complaining about a ( token when pointing at the s? I have no idea even where to start...

The error occurs practically with no other code. The minimal example would be:

#include <string>

int exec_wait(const std::string& path, std::string& stdout, ...)
{
}

The error says:

error: expected ',' or '...' before '(' token
 int exec_wait(const std::string& path, std::string& stdout, ...)
                                                     ^

Anyone has any clues why it's complaining about a ( token when pointing at the s? I have no idea even where to start...

The error occurs practically with no other code. The minimal example would be:

#include <string>

int exec_wait(const std::string& path, std::string& stdout, ...)
{
}
Share Improve this question edited Feb 6 at 18:06 HolyBlackCat 96.3k13 gold badges167 silver badges268 bronze badges asked Feb 6 at 17:39 AlexAlex 1,0771 gold badge10 silver badges27 bronze badges 9
  • 2 Please edit your question to not only contain a full and complete copy-paste of the build output, but also a minimal reproducible example. – Some programmer dude Commented Feb 6 at 17:41
  • 3 stdout might be a macro, like on the compiler I use: #define stdout (__acrt_iob_func(1)). – BoP Commented Feb 6 at 17:48
  • What code are you compiling? – ks1322 Commented Feb 6 at 17:50
  • @BoP It is always a macro: en.cppreference.com/w/cpp/io/c/std_streams. OP - choose a different name, this one is reserved. – Yksisarvinen Commented Feb 6 at 18:00
  • @ks1322 I am trying to compile urBackup code. Is this relevant? – Alex Commented Feb 6 at 18:00
 |  Show 4 more comments

1 Answer 1

Reset to default 3

stdout is a macro defined in standard library: https://en.cppreference.com/w/cpp/io/c/std_streams. It's defined in cstdio, but any standard library header is allowed to #include any other standard library header, and in this case it seems string includes cstdio.

To answer title question: compiler sees code after it is preprocessed (so all macros are expanded). Definition of stdout depends on compiler, but it's likely something like (stuff_here), so compiler sees int exec_wait(const std::string& path, std::string& (stuff_here), ...) and errors on that.

The solution is to choose a different name for your argument.

In the future, avoid any names from this list: https://en.cppreference.com/w/cpp/symbol_index/macro (note that they are mostly UPPERCASE or start with underscore, so they aren't too hard to avoid).

发布评论

评论列表(0)

  1. 暂无评论