external declarations of ptrs and arrays

Stephen Clamage steve at taumet.com
Wed Aug 1 02:19:48 AEST 1990


hmelman at absolut.rtp.dg.com (Howard Melman) writes:

>I have the file declare.c:
>char temp[20]="blah";

>I have the file use.c:
>extern char *temp;

>This causes a core dump.

As well it should.  This is, I believe, in the Frequently Asked Questions
list, or should be.  The declarations "pointer-to" and "array-of" are
NOT equivalent types.  There are some expression contexts where either type
may be used with the same semantics.

"char *temp[20];" means "temp is the first address of an array of 20 chars".
"temp[n]" means "n bytes past temp".

"char *temp;" means "temp is a pointer variable which contains the address
of a char".
"temp[n]" means "n bytes past *temp".
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list