Re: [Exim-dev] Code quality measurements and automated check…

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: Tony Finch
Data:  
Para: Philip Hazel
CC: Andreas Metzler, exim-dev
Assunto: Re: [Exim-dev] Code quality measurements and automated checks
On Thu, 24 Jun 2004, Philip Hazel wrote:
> On Thu, 24 Jun 2004, Andreas Metzler wrote:
>
>> As you just mention compiler warnings: exim needs
>> -fno-strict-aliasing as there are many instances of "dereferencing
>> type-punned pointer will break strict-aliasing rules", caused by casts
>> like "(char **)(&foo)" where foo is a pointer to unsigned char
>> (sourcecode: CSS(foo) with foo being a uchar).
>
> Indeed. That is one of the warnings I have to turn off. I wish the
> original designers of the C standard had thought a bit more about the
> signed/unsigned char issue. It is a *huge* hassle to deal with and I
> have been "gotcha'd" by it many times.


The strict aliasing issue is slightly different. In the code above the
conflict is between a pointer to characters and a pointer to pointers.
The standard says that the compiler may optimise on the assumption that
pointers to different types will never refer to the same memory. This
means that, for example

     int foo(char *a, int *b) {
         bar(a, *b);
         return(*b);
     }


the compiler can optimise away the second dereference of b (if a register
is available which isn't corrupted by the function call) because it knows
that bar() will not alter the memory pointed to by b.

Tony.
--
f.a.n.finch <dot@???> http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 6 TO GALE 8, OCCASIONALLY SEVERE GALE 9 AT
FIRST, VEERING NORTHWEST 5 OR 6. RAIN. MODERATE OR POOR.