daparic
daparic

Reputation: 4444

Why is g++ complaining?

Can somebody please explain this phenomenon?

#include <iostream>
int main() {}

And compile it, gaves:

g++ main.cpp -Dn=1
<command-line>:0:3: error: expected unqualified-id before numeric constant

And here is the complete video. I want to know the complete listing of these reserve thingy, and what they are. My environment is cygwin:

g++ --version
g++ (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Upvotes: 1

Views: 149

Answers (1)

Ollin Boer Bohan
Ollin Boer Bohan

Reputation: 2401

-Dn=1 is defining n as a macro before iostream is included, which means it is redefining every occurrence of n in iostream as 1, which breaks a lot of stuff.

To fix it, pick a different macro name, or move the #define to inside the file after the include.

Upvotes: 7

Related Questions