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: pointer <-> integer round-up


On 20-Mar-2002, Tom Lord <lord@emf.net> wrote:
> 
> I was assuming that there were two intermediate types: one for
> pointer->int, one for int->pointer.  But suppose there is only one:
> If it is intptr_t, then an int->pointer conversion will generate
> the warning we're trying to get rid of.

Right.  But this will only occur on obscure platforms that GCC has
never been ported to yet, and which lack an integer type the same size
as a pointer.

> If it is short, the warning will be supressed, but the conversion incorrect.

Irrelevant, since the intermediate type won't be short.
 
> The point is, the double-cast trick, even if with gigantic CPP
> conditionals to pick the one or two intermediate integer types, is a
> platform-specific solution that only works on some platforms.  It
> doesn't actually make the code any more portable than the single cast
> solution;

The aim is not to make the code more portable.
The aim is to supress a compiler warning.

> it doesn't reliably prevent truncating conversions.

Sure, and it doesn't reliably prevent division by zero either.
How are either of those points relevant?

It doesn't *introduce* any problems with truncating conversions.

> 	Or just not issue these warnings at all on such systems.
> 
> That's really close to an option (on all platforms) which disables
> warnings for conversions marked by explicit casts.  Such an option 
> would satisfy me.

I wouldn't object to such an option.

> Once again, I have this habit -- and I think there are many C
> programmers with the same habit -- of using casts carefully and using
> the warning (or error) system of the compiler to detect various kinds
> of editting error.  You change the type of some variable; an
> assignment or function parameter that was previously correct now
> generates a warning or error; you think about what that assigment
> means across the platforms you're interested in; either you change the
> types of variables further or you decide the conversion is intended
> and add the required cast.  Repeat that until all the warnings
> disappear

Which implies that if, after adding one cast, you still get a warning,
then obviously you need to add another one! ;-)

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.


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