C++ conversion operator to unsigned long does not work

Martin Reinecke martin@MPA-Garching.MPG.DE
Thu Sep 28 07:04:00 GMT 2000


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);
  }

~/tmp>g++ -v test.cc
Reading specs from /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__
-Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686
-Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ test.cc /tmp/ccea4Y4y.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../include/g++-3
 /usr/local/include
 /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/../../../../i686-pc-linux-gnu/include
 /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
End of omitted list.
 /usr/local/appl/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/cc1plus /tmp/ccea4Y4y.ii -quiet -dumpbase test.cc -version -o /tmp/ccGAXDG1.s
GNU C++ version 2.95.2 19991024 (release) (i686-pc-linux-gnu) compiled by GNU C version 2.95.2 19991024 (release).
test.cc: In function `int main()':
test.cc:4: parse error before `long'


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?

Thanks in advance,
  Martin


More information about the Gcc-bugs mailing list