This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C++ conversion operator to unsigned long does not work
- To: Martin Reinecke <martin at MPA-Garching dot MPG dot DE>
- Subject: Re: C++ conversion operator to unsigned long does not work
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Thu, 28 Sep 2000 08:48:34 -0600
- CC: gcc-bugs at gcc dot gnu dot org
- Organization: Rogue Wave Software, Inc.
- References: <39D34FF6.1B1C5F63@mpa-garching.mpg.de>
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