LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   c++ - "index" is a global scope variable in <string>???? (https://www.linuxquestions.org/questions/programming-9/c-index-is-a-global-scope-variable-in-string-629057/)

BrianK 03-18-2008 06:51 PM

c++ - "index" is a global scope variable in <string>????
 
Maybe this is old news, maybe it's no news, but I find it odd that this program compiles at all:

Code:

#include <string>

int main() {
  bool single = true;

  if (index >= 0 && single)
    printf("here %d\n",index);
  else
    printf("not here\n");

  return 0;
}

being that I haven't defined "index" anywhere. (and also haven't included stdio, but I guess that gets included in string).

maybe this is a heads up or maybe someone can enlighten me as to why this works.

fantas 03-18-2008 07:46 PM

"index" is a function (at least under Linux). So basically here it checks for a function address (and finds it).

BrianK 03-18-2008 08:05 PM

Quote:

Originally Posted by fantas (Post 3093286)
"index" is a function (at least under Linux). So basically here it checks for a function pointer (and finds it).

ahhh. interesting. Thanks.


All times are GMT -5. The time now is 05:20 PM.