This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ conversion operator to unsigned long does not work


Martin Reinecke wrote:
> 
> Hi!
> 
> gcc-2.95.2 and the current CVS version fails to compile the following code:
> 
> int main()
>   {
>   int a = 1;
>   unsigned int b = unsigned long(a);
                     ^^^^^^^^^^^^^

This is in error, only a simple-type-specifier (7.1.5.2) is allowed in a
functional cast (5.2.3).

>   }
> 
...
> 
> gcc seems to choke because the name of the type to which a should be converted consists of two tokens.
> I'm not absolutely sure that the code above is legal C++; but if not, how does one write such a conversion
> properly?

Use static_cast<unsigned long>(a) or (unsigned long)a instead.

Regards
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]