Difference between "char *arr" and "char arr[]"
Erik Naggum
enag at ifi.uio.no
Tue Sep 25 09:00:04 AEST 1990
In article <ENAG.90Sep23231057 at hild.ifi.uio.no>, Erik Naggum (I) wrote:
> Let me venture a concise explanation to this difference:
>
> extern char *arr declares an object, containing a
> pointer to a character
>
> extern char arr[] declares a constant pointer to a
> character
In article <26680 at mimsy.umd.edu>, Chris Torek (you) write:
> Concise, yes; correct, no. Both declare objects; the latter declares
> an object that is an array. It IS an array; it is NOT a pointer. The
> confusion occurs because objects that are arrays are *converted into*
> VALUES that are pointers, whenever the value is called for.
Rather, "char arr[14]" declares an array, but "extern char arr[]" only
declares that "arr" is some constant pointer the value of which is to
be resolved by the linker. "char *arr" declares an object, and
"extern char *arr" declares that "arr" is some object the address of
which is to be resolved by the linker.
I think you overlooked the "extern" up there. I follow your arguments
for locally declared objects down to the finest details.
Strictly speaking, I have to correct my own explanation: Neither
declares objects, but instead object names with types and values of
that type to be resolved by the linker (or later, anyhow).
I hope this gets a "concise, no; correct, yes" response, at least.
--
[Erik Naggum] Naggum Software; Gaustadalleen 21; 0371 OSLO; NORWAY
I disclaim, <erik at naggum.uu.no>, <enag at ifi.uio.no>
therefore I post. +47-295-8622, +47-256-7822, (fax) +47-260-4427
More information about the Comp.lang.c
mailing list