arrays vs. pointers

drw at cullvax.UUCP drw at cullvax.UUCP
Thu Mar 12 10:15:21 AEST 1987


bill at voodoo.UUCP (Bill Sears) writes:
> in decl.c:
> 	char Big_buf[512];
> 
> in main.c
> 	main()
> 	    {
> 	    extern char *Big_buf;
> 	    int i;
> 
> 	    for (i = 0; i < 512; i++)
> 		*(Big_buf + i) = 0;
> 	    }

The linker should, ideally, reject this.  If you want to say "extern
char *Big_buf" then you have to say "char *Big_buf" where you define
it.  What you should say is "extern char Big_buf[]".  Your second
example (where both defintion and reference were in the second file)
is probably invalid under any reasonably tight definition of the
language, but you compiler happens to let you get away with it.

Dale
-- 
Dale Worley		Cullinet Software
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
ARPA: cullvax!drw at eddie.mit.edu
Un*x (a generic name for a class of OS's) != Unix (AT&T's brand of such)



More information about the Comp.lang.c mailing list