GIDForums  

Go Back   GIDForums > Site Info and Feedback > GIDNetwork™ > GIDForums™
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Oct-2004, 06:03
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

C++ Syntax Highlighter related question


When you name a variable in C or C++ what are the valid "characters" one can use?

Obviously alphabets are okay, I assume the underscore is also okay... what else?

So, the following is valid variable names?

Code:
something; _somethingelse;
  #2  
Old 25-Oct-2004, 07:39
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by JdS
When you name a variable in C or C++ what are the valid "characters" one can use?

Obviously alphabets are okay, I assume the underscore is also okay... what else?

So, the following is valid variable names?

Code:
something; _somethingelse;

Legal characters in variable names are: Letters, digits. The first character must be a letter. And, of course names are case-sensitive. Key words (if, else, for, float, etc.) are reserved.

Now, the underscore counts as a letter, but note that the C standard says that names with two underscores in a row and names that start with an underscore are reserved for use by the implementation (compiler, linker).

I have never seen a compiler that doesn't allow user names that begin with an underscore. I don't see how they could enforce this since standard library headers have something like the following:

CPP / C++ / C Code:
#ifndef __STDIO_H
#define __STDIO_H

/* stuff here */
#endif

I don't want to seem too pedantic, but I would avoid having any user named item begin with an underscore.


Regards,

Dave
  #3  
Old 25-Oct-2004, 07:47
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Thank you Dave.

What about the dollar sign? Maybe a variable named $myvar?
  #4  
Old 25-Oct-2004, 07:56
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by JdS
Thank you Dave.

What about the dollar sign? Maybe a variable named $myvar?

Nope. Not in C or C++

Regards,

Dave
  #5  
Old 25-Oct-2004, 08:00
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Thank you again and I am moving this to the GIDForums™ Feedback forum where it really belongs.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repetition structure problem and question brookeville C++ Forum 17 29-Oct-2004 17:48
Hmm what seems to be the problem here? error C2061: syntax error pablowablo C++ Forum 5 12-Jun-2004 22:11
question of practice magiccreative C++ Forum 1 06-Feb-2004 07:17
a C input question tmike C Programming Language 1 16-Sep-2003 02:31
'Related articles' php /mysql question JdS MySQL / PHP Forum 4 06-Sep-2002 10:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:12.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.