Oeleboele <hh******@wanadoo.nl> wrote:
OK, I can't understand this exactly:
I have this function: int howdy(void *)
I first past this to the function &aCharArray
I realized later that this should be aCharArray but...
the former version also worked ?
I can't understand why that worked. The only thing I can come up with
is that the compiler gave me a break (although I did not receive any
warnings) Or perhaps the compiler does something like this :
&(aCharArray[0]) ?
Everything worked & works ok but I'm just currieus why.
Normally, whenever an array appears in an expression the compiler
implecitely converts this into a pointer to the first element of
the array - but there's an exception, and that's when you take
the address of the array (or use it as the operand of sizeof),
so 'a' and '&a' (assuming a is an array) evaluate to the same
thing. It's mentioned in section 6.3 of the FAQ and specified in
section 3.2.2.1 of the C89 standard and section 6.3.2.1 of C99
(or at least in the drafts):
Except when it is the operand of the sizeof operator or the
unary & operator (...) an lvalue that has type "array of
type" is converted to an expression that has type "pointer
to type" that points to the initial member of the array
object and is not an lvalue.
But most compilers should give you warning if you do that.
Regards, Jens
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de