external declarations of ptrs and arrays
Bryan Cardoza
bryan at iconsys
Wed Aug 1 02:48:06 AEST 1990
In article <674 at dg.dg.com> 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. When I change my extern declaration in use.c to be:
>
>extern char temp[];
>
>the program works fine. I was under the impression that the two
>declarations were the same. Help...
No so. When using *temp, the contents of temp are used, whereas
when using temp[], the address of temp is used. In M68k assembly
(using the System V/68 assembler syntax) we are talking about the
difference between
mov.l temp,%a0
for *temp and
mov.l &temp,%a0
for temp[]. Sure, you can often use the two the same way in your
C programs, but remember, we're talking about a storage declaration
here, and pointers and arrays are not the same thing.
--
Bryan Cardoza UUCP: uunet!iconsys!bryan
Software Engineer Internet: bryan at iconsys.icon.com
Icon International, Inc. (801) 225-6888
Orem, Utah FAX: (801) 226-0651
More information about the Comp.lang.c
mailing list