Re: Keil c51 interprets &Array as Array. Is that normal?



"Andrey Tarasevich" <andreytarasevich@xxxxxxxxxxx> wrote in message
news:JfqdnVOSad50vmLanZ2dnUVZ_vTinZ2d@xxxxxxxxxxxxxx
Tim Wescott wrote:
On Thu, 10 Apr 2008 12:57:46 -0700, Andrey Tarasevich wrote:


If you want to obtain a "pointer-to-array-of-N-char" in this example, you
need to use the unary '&' explicitly. The following expression

&a

does in fact evaluate to a value of "pointer-to-array-of-N-char" type,
which is 'char (*)[10]' in this case. And the compiler will not
"seamlessly cast" it to "pointer-to-char" type

b = &a; /* ERROR !!! */

as you seem to suggest in your previous message. This is why I disagreed
with it.

--
Best regards,
Andrey Tarasevich


OK, I think we have flogged this to death now. Keil is naughty to treat "p
= &Array" and "p = Array" as the same without any warning, but apart from
that, it may as well treat the two assigments as the same, though the latter
better reflects what is intended.

Of course, if it was:

{
char *Array = malloc(n); // Used to be fixed size, but we progressed. */
/* masses of obscuring data declarations */
char *p1 = Array;
char *p2 = &Array; /* Someone may be in for a nasty shock when they use
*p2 to access Array[0] */
}


then things might be more troubled. And yes, Keil compiles this without a
murmur too. Thank heavens for PCLInt.

Bill



.