[collectd] [PATCH] libiptc: avoid strict-aliasing warnings

Jan Engelhardt jengelh at medozas.de
Tue Mar 9 21:56:54 CET 2010


On Tuesday 2010-03-09 21:39, Alan Pevec wrote:
>> On Tue, Feb 16, 2010 at 09:16:47PM +0100, Alan Pevec wrote:
>>> -             int pos = *(int *)t->data;
>>> +             const unsigned char *data = t->data;
>>> +             int pos = *(const int *)data;
>>
>> I have to admit these changes look a bit like "cast to different types
>> until the compiler is confused", but I don't see any problem arising
>> from those casts either. So if it's fixing a problem for you, it's fine
>> by me. I've applied the changes to the collectd-4.8 branch.
>
>Thanks!
>Well, this was breaking collectd build in Fedora, so I just took the
>upstream patch without much thinking.
>strict-aliasing is confusing indeed, AFAICT solution by Jan is that
>char* is special and may refer any type.

No, the special type you are talking about is void *.

Anyway, the issue here was/is is that gcc did not seem to be able
to track strictness across (int *)t->data, which is why the
assignment was split. The const was only added as a correctness
bonus and did not, as far as I can remember, contribute or fix
the problem either way. It was really the split-into-two-operations.



More information about the collectd mailing list