This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
pointer <-> integer round-up
- From: Tom Lord <lord at emf dot net>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 15 Mar 2002 10:45:42 -0800 (PST)
- Subject: pointer <-> integer round-up
Just to summarize the ideas proposed regarding these warnings:
The issue concerns warnings given (by default and with `-Wall') by
recent versions of GCC for truncating conversions between integers and
pointers. The controversial issue is whether or not such warnings should
be given even when the conversion is marked with an explicit cast.
(Hopefully the names I've given to each proposal are all equally
denigrating, in the name of fairness.)
1. The W.C. Fields Proposal ("Go away, kid, ya bother me")
Everything's fine. The warnings are perfect and very
helpful. Live with it.
2. The Good 'ol Days Were Better Proposal ("It was uphill both
ways, and we liked it!")
Such warnings should not always occur for code containing an
explicit cast. That they do makes the warning system less
helpful. This is, after all, the traditional meaning of a
cast that expresses a default conversion.
Ways to selectively activate or de-activate these
warnings (for explictly cast values) with compiler options
would make everyone happy.
3. The Ostrich Double-Cast Proposal ("All the world is a VAX")
Go with proposal (1). In code, use double casts to take
pointers to a "wide enough" integer type, then a "narrow
enough" integer type for pointer->int. Take integers
to a "narrow enough" integer type, then a pointer type for
int->pointer.
True, nothing in the standard assures us that the narrow
enough and wide enough integer types will both actually exist,
but looking around the room, I don't see any systems
where they don't.
4. The Rube Goldberg/Federal Budget Solution ("Here I have a
blueprint for the future that saves us from worrying about
this today.")
Go with proposal (3) for now. However, in the event of a
system where the suitable integer types are not available,
detect the use of double casts as a special case, and
supress the warning in those cases (on such platforms).
True, a double cast on one of these future systems may
wind up invoking a conversion that is not the same as
the default conversion, but wouldn't most people agree
that that's a pretty obscure objection?
And the prize winning contribution, as far as I'm concerned, goes to
dewar:
Just goes to show that warnings are a difficult area of
discussion :-)
-t