C++ name with leading underscore character not Compiling

Dave Korn dave.korn@artimi.com
Mon Apr 16 09:41:00 GMT 2007


On 16 April 2007 10:34, Chelton Evans wrote:

> I believe it is legal to have a C++ variable name with a leading
>  underscore.

  No.  All names beginning with an underscore are reserved for the
implementation.

  However, the compiler allows it, because for all it knows your code could be
part of the OS or libc that has the legitimate right to use such identifiers.
But technically it's actually undefined behaviour, the reason being that you
may tread on a reserved name.

> A name with two underscores is reserved, so
>  I guess this is illegal. Currently the two cases are reversed.
>  class hat { ... void fred( int __name) ... compiles, but
>  class hat { ... void fred( int _name)... which is legal does not
>  compile.
> 
> Could you confirm or deny the problem.

  I deny it:

/artimi $ cat t.cpp

class hat {

        void fred( int _name);
        void fred2( int __name);
};

/artimi $ g++ -c t.cpp -o t.o -W -Wall
/artimi $

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list