LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06: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, 07: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 01:16 AM.
 
Old 03-18-2008, 08: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



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 03:10 PM
output the path for files whose names include string "string" (case insensitive) sean_zhang Linux - Newbie 1 03-04-2008 11:59 PM
"Broken" envirnment variable (MANPATH) and "/etc/profile.d" question. ErV Slackware 3 03-20-2007 09:42 AM
java variable scope - use of "this" keyword zeppelin147 Programming 1 11-21-2005 10:04 PM
gnome global settings "Help Me!!" or "URGENT" Fascistchicken Linux - Software 3 01-26-2004 06:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration