DevHeads.net

Help with strict-aliasing warning

I'm getting:

/builddir/build/BUILD/gdl-0.9.8/src/basic_pro_jmg.cpp: In function 'void
lib::linkimage(EnvT*)':
/builddir/build/BUILD/gdl-0.9.8/src/basic_pro_jmg.cpp:159:36: warning:
dereferencing type-punned pointer will break strict-aliasing rules
[-Wstrict-aliasing]
(BaseGDL* &) dynFun[count_fun] =
~~~~~~~~~~~~~~~~^
(BaseGDL*) dlsym(module[count], entryName.c_str());

dynFun is defined as:

BaseGDL*(*dynFun[MAXNDLL/2])( EnvT* e);

This is all beyond me. Missing the function pointer argument specification?

Thanks.

Comments

Re: Help with strict-aliasing warning

By Kevin Kofler at 04/12/2018 - 05:51

Orion Poplawski wrote:
Try:

dynFun[count_fun] =
(BaseGDL*(*)(EnvT*)) dlsym(module[count], entryName.c_str());

Kevin Kofler

Re: Help with strict-aliasing warning

By John Reiser at 04/12/2018 - 09:40

Kevin Kofler wrote:
Yes. Introducing a typedef might aid understanding:

typedef BaseGDL* (*dynFun_t)(EnvT* e);
dynFun_t dynFun[MAXDLL/2];
// ...
dynFun[count_fun] = (dynFun_t) dlsym(...);

Re: Help with strict-aliasing warning

By Orion Poplawski at 04/12/2018 - 10:13

On 04/12/2018 07:40 AM, John Reiser wrote:
Thanks!