Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

leading underscores..



Stephen Adler writes:

> I've run across an issue about using underscores in variable
> names. I've been writing software
> under linux for the past 15 years and I've gotten into the habit of
> using underscores in my
> variables names for priviate variables in a class. I tried to compile
> my code on Solaris
> 10 x86 using the gnu compiler and it threw errors because the compiler
> didn't like the
> leading underscore. Does anyone have any comments on this? If a
> leading underscore
> is not used to private variable and functions in classes, what the
> coding standard to indicate
> the variable belongs to the class your coding?

The C standards say that identifiers with a leading underscore are
reserved (i.e. don't use these unless you are writing libc or kernel
code, etc.).  Example:  _write

The C++ standards say that identifiers with a double underscore are
reserved.  Example:  foo__bar

Sure, you might be able to get away with using these identifiers on
certain platforms, but the results are undefined, and, as you can see
very clearly, you will run into problems on other platforms.


Love it or hate it, I have found that the most common way to indicate
that a variable is a member of a class is with a leading "m_" (for
"member").  Like this:

   class T {
     int m_count;
   }

Hope this helps,

--kevin
-- 
GnuPG ID: B280F24E              Never could stand that dog.
alumni.unh.edu!kdc                   -- Tom Waits


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org