2.2.2 Compilation Warnings On Tru64 / Digital Unix

Ludolf Holzheid LHolzheid at bihl-wiedemann.de
Mon Oct 29 17:46:02 GMT 2001


On 29 Oct 2001, at 11:13, Esh, Andrew wrote:

> According to the C language operator precedence rules, the
> application of the '&' operator should come after the application
> of all the other operators used in "&pass[i].lm_pwd". The array
> reference comes first, then the member or union reference "dot".
> Then the address of that location is what is passed to memset. The
> memset is supposed to zero the lm_pwd part of the structure which
> is the i-th element in the "pass" array. 

Yes.

> If the "&" (which reads as 'address of') is ignored, then memset
> will get the -value- of lm_pwd, which is then interpreted as an
> address, and *that* is zeroed. Since the value of lm_pwd is not a
> pointer (lm_pwd is an array of uint8), the memset will probably
> corrupt memory, or cause a segfault. 

No.

C passes arrays 'by reference', i.e. not the contents of the array is 
pushed on the stack but its address.

    If 'pass[i].lm_pwd' is an argument of a function, the
    *address* of the lm_pwd part of the i-th element of pass is
    pushed on the stack. 

In contrast, pointers are regarded as integers and passed 'by value', 
i.e. their value is pushed on the stack.

    If '&pass[i].lm_pwd' is an argument of a function, the
    address of the lm_pwd part of the i-th element of pass is
    computed and this *value* is pushed on the stack. 

That is, with regard to the stack, "&pass[i].lm_pwd" and 
"pass[i].lm_pwd" are just synonymous.

However, the ampersand version passes the address of an array of 
UINT8 by value, and the non-ampersand version passes an array of 
UINT8 by reference, so a compiler doing over-pedantic type checking 
may give a warning, even if a void* is expected.

Just decrease the warning level.

Ludolf




---------------------------------------------------------------
Ludolf Holzheid             Tel:    +49 621 3392723
Bihl+Wiedemann GmbH         Fax:    +49 621 3392239
Flosswoerthstrasse 41       e-mail  LHolzheid at Bihl-Wiedemann.de
D-68199 Mannheim, Germany
---------------------------------------------------------------




More information about the samba-technical mailing list