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 conversion warnings (bogus -Wall warnings)



> The code in question, once again, has an explicit cast:
> 
> 	x = (int)p;
> 
> I am assured by the flow through my program that the value stored in
> `p' was first cast from an integer and that it's range is sufficiently
> constrained that it won't cause a problem on any even vaguely sane
> architecture.   I added the cast to the code precisely to eliminate
> the warnings and to signal that there's a possible value truncation
> here that can't be disproven by the compiler -- but I want that
> well-defined conversion anyway.
> 
> There is no integer type guaranteed to be wide enough to hold values
> from pointers.  So unlike the first warning I asked about, I don't see
> any reasonable "double cast" that solves the problem.

Why not:

      x = (int)(intptr_t)p;

?

-Tim


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