On 11/10/06, Howard Chu <[EMAIL PROTECTED]> wrote:
I see a lot of APIs (e.g. Cyrus SASL) that have accessor functions
returning values through a void ** argument. As far as I can tell, this
doesn't actually cause any problems, but gcc 4.1 with -Wstrict-aliasing
will complain. For example, take these two separate source files:

alias1.c
####

#include <stdio.h>

extern void getit( void **arg );

main() {
        int *foo;

        getit( (void **)&foo);
        printf("foo: %x\n", *foo);
}
####


alias2.c
####
static short x[] = {16,16};

void getit( void **arg ) {
        *arg = x;
}
####

gcc -O3 -fstrict-aliasing -Wstrict-aliasing *.c -o alias

The program prints the expected result with both strict-aliasing and
no-strict-aliasing on my x86_64 box.  As such, when/why would I need to
worry about  this warning?

If you compile with -O3 -combine *.c -o alias it will break.

Richard.

Reply via email to