leading underscores..
Stephen Adler
adler at stephenadler.com
Wed Dec 6 10:29:00 EST 2006
Thanks Kevin,
I'm looking for a coding standard alternative to the one I was using
since the _variable
name is no good for solaris. (its ok for Linux though...) using
m_variable will be an
good workaround.
Thanks again.
Kevin D. Clark wrote:
>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
>
>
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Discuss
mailing list