This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3600: g++ 2.95.3 complains about "unsigned long( 25 )"
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3600: g++ 2.95.3 complains about "unsigned long( 25 )"
- From: crawford at goingware dot com
- Date: 7 Jul 2001 04:19:03 -0000
- Reply-To: crawford at goingware dot com
>Number: 3600
>Category: c++
>Synopsis: g++ 2.95.3 complains about "unsigned long( 25 )"
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Fri Jul 06 21:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Michael D. Crawford
>Release: g++ 2.95.3-5
>Organization:
>Environment:
CygWin on Windows NT Service Pack 6, Pentium III machine.
The gcc I have is from the latest CygWin as of a couple weeks
ago. When 3.0 is available for CygWin I'll try that out too. I
think a slackware package for 3.0 is available for my linux systems, so I'll
try that out sometime soon too. I'm not up to building gcc right now.
>Description:
The code in file Foo.cpp calls unsigned long's conversion
operator to cast an int to an unsigned long. g++ complains:
Foo.cpp:7: parse error before "long"
The code in question compiles (and works) without complaint with Microsoft
Visual C++ version 6 service pack 5, as well is Metrowerks CodeWarrior
version 6.1 for Windows.
>How-To-Repeat:
g++ -c Foo.cpp
>Fix:
surround the unsigned long with parenthesis, so the "unsigned"
is grouped with "long" to make "unsigned long" a unit:
ul = (unsigned long)( 25 );
I'm not clear whether that continues to be unsigned longs
one-parameter constructor conversion operator or just an
old-fashioned c-style cast.
An alternative is to use a typedef that is (as typedef's must be)
a single token. My application is written for the Win32 api, and in
Win32, there is a "typedef unsigned long ULONG;"
ul = ULONG( 25 );
it also works to use a c++ style static cast:
ul = static_cast< unsigned long >( 25 );
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-unknown-content-type-CodeWarrior_cpp; name="Foo.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Foo.cpp"
dm9pZCBGb28oKTsNCg0Kdm9pZCBGb28oKQ0Kew0KCXVuc2lnbmVkIGxvbmcgdWw7DQoJDQoJdWwg
PSB1bnNpZ25lZCBsb25nKCAyNSApOw0KCQ0KCXJldHVybjsNCn0NCg==