On Wed, Dec 22, 2004 at 12:26:03PM +0000, Pete French wrote:
> > Buggy compilers are indefensible, yes, but why try to apologise for it?
> 
> I dont see it as a bug. Without an 'L' the right hand side of that
> expression is a 16 bit int. For which 65536 is out of range. If I
> wrote 'int y = 65535; long x = y;' then I would get the same result for
> the same reason.

Wrong.  With 16-bit int the constant 65536 has type long.

The type of a decimal integer constant without any suffix is the first
of 'int', 'long', 'long long' in which the constant can be represented.
(For C89 it was the first of 'int', 'long', 'unsigned long')

(See 6.4.4.1 in the C99 standard.)

Your example of 'int y = 65535; long x = y;' on the other hand causes
implementation-defined behaviour for 16-bit ints.
(As do all other instances of overflow for signed integer types.)


> 
> The correct line is 'long x = 65535L;' which specifies that the constant
> is a long. In fact aren't situations like this the precise reason for
> having the 'L' as part of the language ?
> 
> > 'long x = 65535;' will not set x to -1, even with 16-bit ints.
> 
> It will and does on certain compilers unfortunately.

No doubt, but if it does the compilers are buggy.


-- 
<Insert your favourite quote here.>
Erik Trulsson
[EMAIL PROTECTED]
_______________________________________________
freebsd-stable@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-stable
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to