add_ssaaaa and C++

Emmanuel Thomé Emmanuel.Thome at inria.fr
Mon May 23 11:10:57 CEST 2005


On Mon, May 23, 2005 at 12:44:15AM +0200, Gabriel Dos Reis wrote:
> You can rant as you like but, the compiler is just doing its job of
> following instructions.  The cast is understood as
> reinterpret_cas<long&>(lvalue_oftype_int) -- which in C speak would be
> (long *) (expression with type int*). 
> Now, do you want the compiler warn that too?

The attached code does give aliasing warning at least in C, and not in
C++.  I think the code is invalid in either case.

Debate off list please, this has nothing to do with gmp.

E.
-------------- next part --------------
#include <stdlib.h>

/*  gcc -Wall -O2 t.c
 *  g++ -Wall -O2 t.c
 */
int main(void)
{
	int a = 0x12345678;
	long *b = (long *) & a;

	b[1] = 0;

	if (a == 0x12345678)
		abort();

	return 0;
}


More information about the gmp-bugs mailing list