cast truncates bits from constant value (8000000000000000 becomes 0)

Derek M Jones derek at knosof.co.uk
Sat Dec 2 07:49:19 EST 2006


Linus,

>> One of the gcc maintainers (Andrew Pinski) told me to set it up that
>> way, so I figured it was safe.
> 
> It _is_ safe, as long as you stick to gcc, and as long as you don't mix 
> signs in your values, for example.
> 
> But we actually want to let people compile even the kernel with other 
> compilers than gcc. Most of the time, that means that we strongly 
> encourage those compiler people to support all the gcc extensions (let's 
> face it, standardization is good, and open standards work better than 
> closed ones, and gcc is the most widely spread open and portable compiler 
> BY FAR, so it would be stupid to _not_ do that).

The C++ Standard explicitly supports enumeration constants not
having type int.  See sentence 858 of
http://www.coding-guidelines.com/cbook/cbook1_0b.pdf
for a discussion of the issues (plus some other sentences).

C compiler vendors, at least those who extend the language, are more
likely to want to follow the C++ rules (which are documented) than the
gcc rules (which are poorly documented).

The C++ way of doing things is also likely to be followed by vendors
whose C compiler is enabled by a command line switch on their C++
compiler (eg, at least one vendor based in Seattle).

-- 
Derek M. Jones                              tel: +44 (0) 1252 520 667
Knowledge Software Ltd                      mailto:derek at knosof.co.uk
Applications Standards Conformance Testing    http://www.knosof.co.uk



More information about the Linuxppc-dev mailing list