This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Undefined behavior in 950605-1.c


Momchil Velikov <velco@fadata.bg> writes:

|> IMHO, gcc.c-torture/execute/950605-1.c (pasted below) provokes
|> undefined behavior according to ISO 9899:1999 6.5.2.2 [#6]
|> 
|>        ... If the function is defined with a type that does not
|>        include a prototype, and the types of the arguments after
|>        promotion are not compatible with those of the parameters after
|>        promotion, the behavior is undefined, except for the following
|>        cases:
|> 
|>          -- one promoted type is a signed integer type, the other
|>             promoted type is the corresponding unsigned integer type,
|>             and the value is representable in both types;
|> 
|> f (c)
|>     unsigned char c;
|> {
|>   if (c != 0xFF)
|>     abort ();
|> }
|> 
|> main ()
|> {
|>   f (-1);
|>   exit (0);
|> }
|> 
|> IOW, the value -1 is not representable in the promoted type of the
|> formal parameter of ``f''.

The promoted type of the formal parameter of f is either int or unsigned
int, and -1 is representable in both types.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]