Search code examples
c++cygwin

Error in Cygwin seems to mismatch the description


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, ...)
{
}

Solution

  • 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).