------- Comment #9 from edwintorok at gmail dot com 2009-04-25 14:22 ------- (In reply to comment #6) > No, not if it is inlined (and if not you can as well use memcpy). > > You can also do (GCC extension) > > union union_t { > unsigned un; > char c[4]; > }; > > unsigned bar(char *x) > { > union union_t u; > u.c[0] = x[0]; > u.c[1] = x[1]; > u.c[2] = x[2]; > u.c[3] = x[3]; > return u.un; > } > > but that will even generate worse code with GCC than the > memcpy (it's even horrible code).
Hmm, looks like the only way out is for me to put #if defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) and use memcpy. Either that or add a configure rule to add -fno-strict-aliasing. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39895