Global and Extern Pointers, Arrays
Xiang-Min Wang
xwang at gmuvax2.gmu.edu
Fri May 31 07:07:30 AEST 1991
In article <AJ3U.91May22202642 at agate.cs.virginia.edu> aj3u at agate.cs.virginia.edu (Asim Jalis) writes:
>I just figured out the following bug in my program. I had a global
>array, with some initialized value that I was also declared an extern
>pointer in the other files that accessing it. This turns out to be a
>no-no. The bug went away when I changed the extern definition to an
>array also.
>
>Here is the code:
>
>file.1
> struct x px[1] = { ... };
>
>file.2
> extern *px /* boinks */
> extern px[] /* works */
>
>Any ideas as to why this is?
>
>Asim Jalis.
Hi, Asim. in your file 'file.2', you should declare px as
extern struct x px[1]
telling the compiter that px[1] is of type 'struct x' but do not need bother
allocating memory for it.
as to why your second solution works, well, there are a lot of luck out there
in c programming. so good luck.
xwang
More information about the Comp.lang.c
mailing list