[comp.lang.c] Please understand!

hutch@sdcsvax.UCSD.EDU (Jim Hutchison) (12/14/86)

In article <1391@umd5> carl@umd5.umd.edu.UUCP (Carl Symborski) writes:
>/*
>
>Well all this talk about bugs in Dave Wecker's VT100 program which don't
>happen under MANX and do happen under LATTICE has got me started.  Darnit
>why dosn't the beep thing work when VT100 is compiled under LATTICE!
>...
#ifdef MODULE_MAIN
>...
>UBYTE Audio_AllocMap[4] = {1, 8, 2, 4};
>...
#else
>...
>extern UBYTE Audio_AllocMap[];
>...
>external array of type UBYTE.  We DON'T know how long it is, so when we say
>"sizeof(Audio_AllocMap)" we should expect zero maby one... but not four!!!!

Yes, a very nice trick.  It is typed as an array, and externed as an array.
If I say sizeof, the compiler can belch at me, or do the proper thing.  I can
not find what Lattice does as acceptable (silence is leaden :-).  The extern
here should say 4, or 0 and a warning that the compiler is not able to find
a size.

Why 0?  Because if you can't get the right size, and the user to too lazy to
make up for it, you should not introduce cryptic bugs!!!

Here is what the 4.3bsd compiler from berkeley says:
t1.c:	/* containing the declaration */
t2.c:	/* containing the extern      */
"t2.c", line 8: warning: sizeof returns 0

t1.c>
char string[13] = "Hi I am Jim.";
		/* 123456789-123 */
main()
{
	write(1,string,sizeof(string));
	second();
}
t2.c>
extern char string[];

second()
{
	write(1,string,sizeof(string));
}
<>

-- 
    Jim Hutchison   		UUCP:	{dcdwest,ucbvax}!sdcsvax!hutch
		    		ARPA:	Hutch@sdcsvax.ucsd.edu
Fig is a 5 stage concept.