vamaddur's blog

By vamaddur, history, 3 weeks 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.

 
 
 
 

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

#define index index________

»
3 weeks ago, # |
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

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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