This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: varargs, 64-bit targets, and strict-aliasing warnings
Joseph> uint64_t is unsigned long rather than unsigned long long
Joseph> on those 64-bit targets. Thus the pointer cast creates a
Joseph> pointer which foo cannot safely dereference without
Joseph> converting back to a pointer to uint64_t.
Thanks for the explanation. However I'm still a little hazy on what's
being done that's forbidden by the strict-aliasing rules. For one
thing, the warning produced by gcc is at least a little misleading:
casting a uint64_t * to another pointer type is (as far as I know)
perfectly legal and there is no type-punned pointer anywhere to be
found. And of course no pointer is being dereferenced at the line gcc
warns about.
Also, hiding the cast from gcc by first casting to void * and then
going through an inline function shuts gcc up (as shown below), which
seems odd. Does this void * cast make gcc relax its aliasing rules?
#include <stdint.h>
void foo(unsigned long long *y);
static inline void baz(void *z)
{
foo((unsigned long long *) z); /* no warning here */
}
void bar(void)
{
uint64_t x;
foo((unsigned long long *) &x); /* warn here */
baz((void *) &x); /* but not here */
}
(By the way, I now realize that varags have nothing to do with the
warning -- I got confused because of how I distilled my original code)
Thanks,
Roland