On Fri, 13 Aug 2010 19:44:38 +0200, Cristian Morales Vega <cmorve69@yahoo.es> wrote:
The thing is the offending code is
"*(void **)(&comp_compress) = dlsym(handle, "comp_compress");"
So, the question: could gcc -O2 really break that code? Or that's a false warning and I can be 100% safe ignoring it?
Yes, it can. The C compiler assumes the normal aliasing rules, i.e. that objects of one type can only be accessed through pointers of the same type or char/void pointers. Therefor the compiler will organize the code depending on whether it finds other accesses or not. And before you remark it, there is a difference between 'void **' and 'void *' and the standard does only cover 'void *'. The only way I know of to correct the code would be to use a union, i.e. for the csine example { void *handle; double (*cosine)(double); char *error; union{ void *vp; double (*cos)(double); }pun. handle = dlopen("libm.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "%s\n", dlerror()); exit(EXIT_FAILURE); } dlerror(); /* Clear any existing error */ pun.vp = dlsym(handle, "cos); cosine = pun.cos. if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(EXIT_FAILURE); } GCC guarantees that the union trick works. Philipp -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-packaging+help@opensuse.org