Finding Available Length Of Strings...

Blair P. Houghton bhoughto at cmdnfs.intel.com
Tue Nov 13 03:59:49 AEST 1990


In article <921 at inews.intel.com> bhoughto at cmdnfs.intel.com (Blair P. Houghton) writes:
>"pointers to arrays containing chars"?
>    typedef char A[SIZE];
>    A *foo;
>
>Note also that, since it is a pointer
>to an array rather than a pointer to char, you have to get
>the chars through `*foo[i]' or `**foo' rather than `*foo'
>or `foo[i]'.

I'm sorry, this is wrong.  The `[]' have a higher precedence
than the `*', so it would have to be `(*foo)[]' for the subscripted
version, if `foo' were a pointer to a pointer.

In order to use `foo' (as anything other than NULL)
you have to provide an array of the proper type, properly
allocated, and then assign the "address" of that array to `foo'. 
But, in the act of assigning that address, you turn the
array into the pointer to its first element.  There is in
fact no way to get the address of an array without actually
getting the address of the first element.  This still does not
make the two of them compatible types[*].  However, it means
that `**foo' is not correct.

`*foo' is the proper pointer dereference to get `array[0]',
`foo[i]' is the proper subscripted version, even though
`foo' is a proper pointer-to-array.

[*]  The assignment `foo = &bar' is right, the assignment
`foo = bar' is incorrect (gcc -ansi just produces a
warning, but, if you believe in the Pointer Fairy (as you
and Doug know I do :-), you believe that all pointers are the
same, anyway, so `foo = bar' works even though it's hubris;
but don't trust it).

				--Blair
				  "The PF still owes me a quarter.
				   She's probably just waiting for those
				   pointer-subtraction semantics I promised
				   I'd post... :-/"



More information about the Comp.lang.c mailing list