[ECOS] Re: casts to a type other than an integral or enumeration type in a constant-expression

Andreas Schwab schwab@suse.de
Thu Feb 13 13:36:00 GMT 2003


Jonathan Larmour <jifl@eCosCentric.com> writes:

|> Nathan Sidwell wrote:
|> > Jonathan Larmour wrote:
|> > 
|> >>> |>       case (int) SIG_DFL:
|> > 
|> >>>
|> >>> This code is completely bogus anyway, even if it might be valid.
|> >>> Casting
|> >>> a pointer to int is dubious at best and will fail miserably if sizeof
|> >>> (__sighandler_t) > sizeof (int).
|> >>
|> >>
|> >>
|> >> Assuming I'm thinking of the right bit of code, Fred was paraphrasing
|> >> the code. The "int" is actually an eCos typedef set by the hardware
|> >> abstraction layer so _will_ be correct for the hardware.
|> >>
|> >> The warning is certainly misleading at best as an int is certainly an
|> >> integral type ;-). From a quick read of the C++ standard, I can't see
|> >> any problem with this code.
|> > the problem is SIG_DFL is probably,
|> >     typedef void (*__sighandler_t) (int);
|> >     #define SIG_DFL ((__sighandler_t)0)
|> 
|> Indeed it's like that. But the whole thing is cast to an int, so the
|> expression as a whole has integral type. From the C++ standard 6.4.2 para
|> 2 that's all that's required, the way I read it. Having a non-integral
|> type in an intermediate stage should make no difference.

But 5.19[#1] also says about integral constant expressions: "Only type
conversions to integral or enumeration types can be used.".  A function
cast is not valid according to this clause.

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."



More information about the Gcc-bugs mailing list