Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Reserved identifiers in C++ vs C?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
eli.friedman@gmail.com  
View profile  
 More options Aug 2 2009, 3:43 am
Newsgroups: comp.std.c++
From: "eli.fried...@gmail.com" <eli.fried...@gmail.com>
Date: Sun, 2 Aug 2009 01:43:18 CST
Local: Sun, Aug 2 2009 3:43 am
Subject: Reserved identifiers in C++ vs C?
The C++ standard says that "Each name that contains a double
underscore _ _ or begins with an underscore followed by an uppercase
letter (2.11) is reserved to the implementation for any use."  The
equivalent section of C99 says "All identifiers that begin with an
underscore and either an uppercase letter or another underscore are
always reserved for any use."  Is it intentional that using
identifiers like kw__for (with two underscores) is legal in C but not C
++?  If so, why?

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Francis Glassborow  
View profile  
 More options Aug 2 2009, 10:39 pm
Newsgroups: comp.std.c++
From: Francis Glassborow <francis.glassbo...@btinternet.com>
Date: Sun, 2 Aug 2009 20:39:35 CST
Local: Sun, Aug 2 2009 10:39 pm
Subject: Re: Reserved identifiers in C++ vs C?

eli.fried...@gmail.com wrote:
> The C++ standard says that "Each name that contains a double
> underscore _ _ or begins with an underscore followed by an uppercase
> letter (2.11) is reserved to the implementation for any use."  The
> equivalent section of C99 says "All identifiers that begin with an
> underscore and either an uppercase letter or another underscore are
> always reserved for any use."  Is it intentional that using
> identifiers like kw__for (with two underscores) is legal in C but not C
> ++?  If so, why?

The original motivation behind reserving all uses of __ to the
implementation was to provide a mechanism for name mangling (i.e.
encoding the function signature in the name used by the compiler) While
there are other ways that name mangling (or more generally overloading
of function names) could have been supported the choice was motivated by
   the need to support code translators (e.g. CFront)that converted C++
code to C and so needed to keep withing the character set supported by C.
Changing that rulle would require a rewrite of sections of most current
C++ implementations to no great gain.

In practice __ is rarely used in C and where it is a C++ compiler will
normally be able to cope with it.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Kanze  
View profile  
 More options Aug 2 2009, 10:38 pm
Newsgroups: comp.std.c++
From: James Kanze <james.ka...@gmail.com>
Date: Sun, 2 Aug 2009 20:38:26 CST
Local: Sun, Aug 2 2009 10:38 pm
Subject: Re: Reserved identifiers in C++ vs C?
On Aug 2, 9:43 am, "eli.fried...@gmail.com" <eli.fried...@gmail.com>
wrote:

> The C++ standard says that "Each name that contains a double
> underscore _ _ or begins with an underscore followed by an
> uppercase letter (2.11) is reserved to the implementation for
> any use."  The equivalent section of C99 says "All identifiers
> that begin with an underscore and either an uppercase letter
> or another underscore are always reserved for any use."  Is it
> intentional that using identifiers like kw__for (with two
> underscores) is legal in C but not C ++?

Yes.

> If so, why?

Historical reasons.  Some early C++ compilers used C as an
intermediate language.  Internally generated symbols used double
underscore, which is legal in C; by forbidding it in C++, they
ensure that these symbols can never conflict with a user defined
symbol.

--
James Kanze (GABI Software)             email:james.ka...@gmail.com
Conseils en informatique orient e objet/
                    Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Karcher  
View profile  
 More options Aug 3 2009, 1:30 pm
Newsgroups: comp.std.c++
From: use...@mkarcher.dialup.fu-berlin.de (Michael Karcher)
Date: Mon, 3 Aug 2009 11:30:41 CST
Local: Mon, Aug 3 2009 1:30 pm
Subject: Re: Reserved identifiers in C++ vs C?
eli.fried...@gmail.com <eli.fried...@gmail.com> wrote:
> always reserved for any use."  Is it intentional that using
> identifiers like kw__for (with two underscores) is legal in C but not C
> ++?  If so, why?

If it is intentional, I suppose that is to have a namespace for
C++-to-C-translators like Cfront to use for mangled names.

Regards,
   Michael Karcher

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »