LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-18-2008, 07:51 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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.
 
Old 03-18-2008, 08:46 PM   #2
fantas
Member
 
Registered: Jun 2007
Location: Bavaria
Distribution: slackware, xubuntu
Posts: 143

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

Last edited by fantas; 03-19-2008 at 02:16 AM.
 
Old 03-18-2008, 09:05 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by fantas View Post
"index" is a function (at least under Linux). So basically here it checks for a function pointer (and finds it).
ahhh. interesting. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert "string" type to "char * " in c++ pranavojha Programming 18 06-05-2008 04:10 PM
output the path for files whose names include string "string" (case insensitive) sean_zhang Linux - Newbie 1 03-05-2008 12:59 AM
"Broken" envirnment variable (MANPATH) and "/etc/profile.d" question. ErV Slackware 3 03-20-2007 10:42 AM
java variable scope - use of "this" keyword zeppelin147 Programming 1 11-21-2005 11:04 PM
gnome global settings "Help Me!!" or "URGENT" Fascistchicken Linux - Software 3 01-26-2004 07:27 PM


All times are GMT -5. The time now is 10:30 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration