On 01.06.2012 14:22, Philip Martin wrote: > GCC gives a compiler warning where the COPY_TWO_BYTES macro is used. A > typical warning is: > > ../src/subversion/libsvn_subr/string.c:971:11: warning: dereferencing > type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] > COPY_TWO_BYTES(dest, decimal_table[(apr_size_t)number]); > ^ [...]
> Is the warning something we can ignore? My understanding of C aliasing > is that writing to memory is only supposed to happen as the declared > type of that memory. > > Is COPY_TWO_BYTES a significant optimisation? On Linux we can avoid the > warning by simply using > > memcpy(dest, source, 2) > > since that memcpy call will be inlined these days. > I think it's OK if that macro becomes an alias for memcpy. On modern systems I'd even expect it to be faster than the current code, since a properly inlined memcpy will know when to pick word-size over byte-size operations, since it'll know the alignment of the source and target (which this macro doesn't). -- brane