Difference between "char *arr" and "char arr[]"

Karl Heuer karl at haddock.ima.isc.com
Tue Sep 25 13:36:44 AEST 1990


In article <ENAG.90Sep25005953 at hild.ifi.uio.no> enag at ifi.uio.no (Erik Naggum) writes:
>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.

I disagree.  Both are *declarations*; the one without "extern" happens to also
serve as a *definition*.  So I would say that "char arr[14]" declares an array
and (being a definition) also causes storage to be allocated for it (probably
by a linker), while "extern char arr[]" declares an array and causes the name
"arr" to be associated with the same storage that was allocated under that
name in some other compilation unit.

There are no pointers (in the C sense) involved here, at least not until such
time as the name "arr" is used in an rvalue context.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list