"Richard M. Hartman" <[EMAIL PROTECTED]> wrote in message
news:53064@palm-dev-forum...
>
>
>
> "Steve Mann" <[EMAIL PROTECTED]> wrote in message
> news:52855@palm-dev-forum...
> >
> > At 1:23 AM -0500 6/13/01, Ben Combee wrote:
> >
> > >Actually, if you have an array, &name is the same as name.  See ISO
C
> > >(1999), $6.3.2.1 part 3, array names get converted to pointers
except
> > >when used with sizeof or the '&' operator.
> >
> > Thanks Ben. I learn something new every day. My comment is based on
> > the C++ compiler complaining every time I accidentally do that.
> >
>
> Great ... enough people make a misteak and it becomes codified.
>
> Even though the standard apparently allows "&name", it is
counterintuitive
> to people who are aware of how the address-of operator works since it
> is essentially an exception to the normal operation of the operator.
>
> Not to mention whether or not the compiler implements ISO C, 1999
edition.
> And even if this one does, will the next one you use?
>
> I'd stick w/ the unadorned array name and/or explicitly taking the
> address of the zeroth element.
>
> btw: ok, so this is in the C standard ... but Steve mentions the C++
> compiler complaining, can somebody check the latest C++ standard
> and see what it has to say on the subject?  If C standard says it
> supports this abuse, but the C++ standard doesn't ... do you really
> want to get into the habit of using it?

Richard, I just checked my copy of ISO C++ (1998) and rechecked my ISO C
(1999) spec.

C++ requires that the operand for '&' be an lvalue.  An array name is an
lvalue.

This code is legal:

    Int16 fooA[] = { 1, 2, 3, 4, 5 };

    Int16 (*foo)[5] = &fooA;

but this line is not:

    Int16 *bar = &fooA;

In both C and C++, &fooA is correctly represented as a pointer to an
array of 5 Int16 values.  That pointer type is NOT equivalent to a
pointer to Int16, and there is no implicit conversion.

I was wrong in my initial reading -- the standard is really confusing in
this area and it took several readings before I was able to grasp all
the syntax.  I'm sorry for my mis-posting.



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to