This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: typeof and bitfields
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: <gdr at integrable-solutions dot net>
- Cc: "'Ian Lance Taylor'" <ian at airs dot com>,"'Neil Booth'" <neil at daikokuya dot co dot uk>,"'Matt Austern'" <austern at apple dot com>,<gcc at gcc dot gnu dot org>,"'Andrew Pinski'" <pinskia at physics dot uc dot edu>
- Date: Fri, 14 Jan 2005 19:39:27 -0000
- Subject: RE: typeof and bitfields
> -----Original Message-----
> From: gdr
> Sent: 14 January 2005 16:49
> "Dave Korn" writes:
>
> | > -----Original Message-----
> | > From: gcc-owner On Behalf Of Ian Lance Taylor
> | > Sent: 14 January 2005 03:03
> |
> | > I think the right semantics are for typeof to return the
> underlying
> | > type, whatever it is, usually int or unsigned int. Perhaps just
> | > return make_[un]signed_type on the size of the mode of
> the bitfield,
> | > or something along those lines.
> | >
> | > If we implement that, and document it, I think it will follow the
> | > principle of least surprise.
> | >
> | > I don't see how giving an error is helpful.
> | >
> | > Ian
> |
> | That seems _really_ wrong to me.
> |
> | If typeof (x) returns int, then I ought to be able to
> store INT_MAX in there
> | and get it back, shouldn't I? Otherwise, why not return
> typeof(char)==int as
> | well? They've got the same 'underlying type' too; they
> differ only in size;
> | there's no reason to treat bitfields and chars differently.
>
> That is an argument for not returning an int. It is not an argument
> for issueing error. Why not return int_with_2bits?
>
> -- Gaby
Pardon me, yes, I didn't follow through the argument as far in my post as I
had done in my head, but I certainly agree: if it's going to be allowed to apply
typeof to bitfields, then it can certainly return some custom type value that
would match only other bitfields of the same size and qualification. That seems
eminently suitable to me; I agree with your conclusion completely.
cheers,
DaveK
--
Can't think of a witty .sigline today....