Topic: Do "leading underscore member names" violate ANSI-Standards ?


Author: "Pavel Mayer" <pavel@datango.de>
Date: 1999/12/14
Raw View
In the new coding rules for our company we would like to have the following
naming rule:

[xx] Private class members are lower case and are prefixed with the letter
'_'.

Looking at various existing style guides, some of them ban identifiers
starting with underscore because of the following reason:

<>
>From the ANSI C Specification (9899:1990(E)) 7.1.3: "All identifiers that
begin with an underscore and either an uppercase letter or another
underscore are always reserved".

_[A-Z_][0-9A-Za-z_]*

"All identifiers that begin with an underscore are always reserved for use
as identifiers with file scope."

_[a-z][0-9A-Za-z_]*
</>

Does this specification apply to C++ as well ?

Does our desired naming rule violate the standard ?

Pavel Mayer
pavel@datango.de
---
[ 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: James Kuyper <kuyper@wizard.net>
Date: 1999/12/14
Raw View
Pavel Mayer wrote:
>
> In the new coding rules for our company we would like to have the following
> naming rule:
>
> [xx] Private class members are lower case and are prefixed with the letter
> '_'.
>
> Looking at various existing style guides, some of them ban identifiers
> starting with underscore because of the following reason:

On a conforming implementation, _[a-z0-9] would be safe, as long as it's
not used at file scope. However, many implementators misunderstand the
reserved names rules, and have created non-conforming implementations
where those would not be safe. You'll have to decide whether or not to
cater to such implementations.

> >From the ANSI C Specification (9899:1990(E)) 7.1.3: "All identifiers that
> begin with an underscore and either an uppercase letter or another
> underscore are always reserved".

That's correct. Since you specified lower case letters, there's no
conflict with your coding rules.

...
> "All identifiers that begin with an underscore are always reserved for use
> as identifiers with file scope."

Correct. Class members have class scope, not file scope, so you don't
need to worry about this rule, only about the previous one.

...
> Does this specification apply to C++ as well ?

The C++ rules are very similar, but they go a little farther. You also
don't want '__' anywhere inside the name.

> Does our desired naming rule violate the standard ?

Add a note about '__' inside member names, and I think you'll be safe.


[ 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: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/12/14
Raw View
In article <832gs6$qrt$1@newsread.do.de.uu.net>, pavel@datango.de
says...

[ ... ]

> >From the ANSI C Specification (9899:1990(E)) 7.1.3: "All identifiers that
> begin with an underscore and either an uppercase letter or another
> underscore are always reserved".
>
> _[A-Z_][0-9A-Za-z_]*

The C++ spec has tighter constraints: in particular, an identifier
that contains two underscores in a row _anywhere_ (rather than just at
the beginning) is reserved.

--
    Later,
    Jerry.

The universe is a figment of its own imagination.


[ 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: "Pavel Mayer" <pavel@datango.de>
Date: 1999/12/15
Raw View
Please read the thread on "comp.lang.c++.moderated", where I orginally
submitted this question, before I found out that "comp.std.c++" might be the
apropriate place for out. However, some really helpful responses appeared on
"comp.lang.c++.moderated" even before my posting appeared here, so the
discussion is now on "comp.lang.c++.moderated" and should be continued
there.

Sorry for any inconveniences

Pavel Mayer




[ 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              ]