Topic: leading underscore legal for member variables?


Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/09/05
Raw View
Martin von Loewis <loewis@informatik.hu-berlin.de> wrote:
>brownsta@concentric.net (Stan Brown) writes:
>
>> That would imply, if I'm reading it correctly, that programs *may*
>> declare and use identifiers that start with an underscore and a lower-
>> case letter (or an underscore and a digit, I suppose). Am I correct?
>
>That is correct. The convention you describe has been common for
>years, and the wording in the standard just fits with this convention.

It is certainly legal to use names like "_member" (but not "_Member")
for this or any other purpose.  However, it's unwise, because many
compiler implementers somehow believe that you won't use them, and
they define their own macros or even keywords with such names.

If you stick with scrupulous implementers this isn't a problem, but
the overwhelming majority of compilers are not sold by scrupulous
implementers.

[ moderator's note: Although "scrupulous" is often used to mean
  "ethical", it also means "painstaking", which I'm sure is what
  Nathan had in mind.  -sdc ]

--
Nathan Myers
ncm@nospam.cantrip.org  http://www.cantrip.org/



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: brownsta@concentric.net (Stan Brown)
Date: 1998/09/04
Raw View
I posted this to comp.lang.c++.moderated 48 hours ago, but it never
appeared (on my server or on Deja News). That's probably a blessing in
disguise, since it's really a question about the standard.

Briefly, the folks on my project are proposing a leading underscore for
member variable names. My query is simply, is this legal, if the next
character is a lower-case letter?

CD2 says at subclause 2.10(2):

"In addition, identifiers containing a double underscore (_ _) or
beginning with an underscore and an upper-case letter are reserved for
use by C++ implementations and standard libraries and shall not be used
otherwise; no diagnostic is required."

That would imply, if I'm reading it correctly, that programs *may*
declare and use identifiers that start with an underscore and a lower-
case letter (or an underscore and a digit, I suppose). Am I correct?

Because of the time lag in Usenet propagation, I'd appreciate an email
copy of posted responses. Thanks!

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
                      http://www.concentric.net/%7eBrownsta/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1998/09/04
Raw View
brownsta@concentric.net (Stan Brown) writes:

> That would imply, if I'm reading it correctly, that programs *may*
> declare and use identifiers that start with an underscore and a lower-
> case letter (or an underscore and a digit, I suppose). Am I correct?

That is correct. The convention you describe has been common for
years, and the wording in the standard just fits with this convention.

Regards,
Martin


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: sbnaran@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/09/04
Raw View
On 04 Sep 98 09:28:47 GMT, Stan Brown <brownsta@concentric.net> wrote:

>Briefly, the folks on my project are proposing a leading underscore for
>member variable names. My query is simply, is this legal, if the next
>character is a lower-case letter?

I don't know.  But if you prefix the underscore with a lower case letter
you can express something useful about your variable that helps a lot
for readability.

class X
{
     int d_variable1; // member variable
     static int s_variable2; // static variable
     int m_variable3; // member variable
     int x_variable4; // alternative representation of another member variable
};


--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]