vamaddur's blog

By vamaddur, history, 8 years ago, In English

When I name a variable "index" in my C++11 code, it successfully compiles with MinGW in CodeBlocks on my PC.

Picture Proof #1

However, on any online compiler/IDE (in this case, Ideone), I get a compile-time error.

Picture Proof #2

How can I make my compiler and/or IDE identify reserved words and prevent me from using them by accident?

I know it's a minor problem, and I could easily circumvent it by "misspelling" variable names (as I am doing now; e.g. prevy instead of prev), but I would still like to fix it.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by vamaddur (previous revision, new revision, compare).

»
8 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

see https://linux.die.net/man/3/index .

#define index index________

»
8 years ago, hide # |
Rev. 2  
Vote: I like it +10 Vote: I do not like it

probably some library in the header is using the same variable/function name, just define the name as some random garbage at the start of the code

  • »
    »
    8 years ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    i clicked on this post expecting to comment the same thing again but i discovered me from 8 months ago already did the job

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

There was similar problem with read variable: http://mirror.codeforces.com/blog/entry/46466

»
8 years ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Simply no using namespace std;