Why is g++ complaining?









up vote
0
down vote

favorite












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.









share|improve this question





















  • iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
    – Peter
    Nov 10 at 3:35














up vote
0
down vote

favorite












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.









share|improve this question





















  • iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
    – Peter
    Nov 10 at 3:35












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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.









share|improve this question













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.






c++ g++






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 0:05









ifelsemonkey

539612




539612











  • iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
    – Peter
    Nov 10 at 3:35
















  • iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
    – Peter
    Nov 10 at 3:35















iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
– Peter
Nov 10 at 3:35




iostream distributed with your compiler uses n somewhere, and the only way to avoid it is not to #define n anywhere before including <iostream>. <iostream> shouldn't do do that (since, in C++, n is not a reserved identifier) but if it does your only option is to avoid using that macro name. It is rare in C++ to actually need to define/use any macro, since there are alternatives that are usually considered preferable. So your first option is not to use macros. If you insist on using macros (usually not a smart call) then either use different names or use a different compiler.
– Peter
Nov 10 at 3:35












1 Answer
1






active

oldest

votes

















up vote
5
down vote













-Dn1 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.






share|improve this answer




















  • Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
    – ifelsemonkey
    Nov 10 at 0:19







  • 1




    " I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
    – Slava
    Nov 10 at 0:23










  • The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
    – user4581301
    Nov 10 at 0:29










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234836%2fwhy-is-g-complaining%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote













-Dn1 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.






share|improve this answer




















  • Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
    – ifelsemonkey
    Nov 10 at 0:19







  • 1




    " I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
    – Slava
    Nov 10 at 0:23










  • The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
    – user4581301
    Nov 10 at 0:29














up vote
5
down vote













-Dn1 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.






share|improve this answer




















  • Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
    – ifelsemonkey
    Nov 10 at 0:19







  • 1




    " I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
    – Slava
    Nov 10 at 0:23










  • The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
    – user4581301
    Nov 10 at 0:29












up vote
5
down vote










up vote
5
down vote









-Dn1 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.






share|improve this answer












-Dn1 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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 0:14









Ollin Boer Bohan

1,365310




1,365310











  • Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
    – ifelsemonkey
    Nov 10 at 0:19







  • 1




    " I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
    – Slava
    Nov 10 at 0:23










  • The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
    – user4581301
    Nov 10 at 0:29
















  • Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
    – ifelsemonkey
    Nov 10 at 0:19







  • 1




    " I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
    – Slava
    Nov 10 at 0:23










  • The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
    – user4581301
    Nov 10 at 0:29















Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
– ifelsemonkey
Nov 10 at 0:19





Huh? And how are we to avoid these collisions? Great, that it gave a compile error. Else, no compile errors, and it changes the underlying c++ library behavior. Do you know where to find the complete listings of these thingy? I like to dynamically defined my macro values at compilation time.
– ifelsemonkey
Nov 10 at 0:19





1




1




" I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
– Slava
Nov 10 at 0:23




" I like to dynamically defined my macro values at compilation time." 1 - use all uppercase letters identifiers 2 - use longer names
– Slava
Nov 10 at 0:23












The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
– user4581301
Nov 10 at 0:29




The only way to avoid collisions with macro substitutions is to not collide. Use better names and avoid macros.
– user4581301
Nov 10 at 0:29

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234836%2fwhy-is-g-complaining%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo