Could egcs warn at (int*)(int)(x)?

Richard Henderson rth@cygnus.com
Mon Dec 15 10:37:00 GMT 1997


On Mon, Dec 15, 1997 at 06:34:46PM +0100, Tobias Polzin wrote:
> Is there any possibility to get warnings for things like:
>    int* foo=(int*)((int)bar + delta);

We do already, and have done so for quite some time.  No extra
warning flags are necessary, c.f. "gcc -c z.c":

void f(int *bar, int delta)
{
  int* foo=(int*)((int)bar + delta);
}

z.c: In function `f':
z.c:3: warning: cast from pointer to integer of different size
z.c:3: warning: cast to pointer from integer of different size

> Or even for
>    int  delta= long(newaddress)-long(oldaddress).

Maybe, but I always found these loss of precision warnings to
be more annoying than helpful.  It happens way too often in
normal code.

Almost all 64-bit errors are caught by the ptr/int warnings.


r~



More information about the Gcc mailing list