Блог пользователя vamaddur

Автор vamaddur, история, 6 лет назад, По-английски

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.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

#define index index________

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

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

  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

Simply no using namespace std;