runtime 'sizeof()'?

Robert Viduya robert at gitpyr.UUCP
Sun Jan 20 13:36:04 AEST 1985


[]

Judging from mail I've recieved about the subject, I think I was a bit
unclear about the problem.  This should clear things up.

The problem is that the sizeof operator produces different answers
when used in two different source files.  I can declare the following
in one source file:

	  ...

	struct s a[] = { 
		{ "....",0,0,0 },
		{ ",,,,",1,1,1 },
	};

	  ...

	b = sizeof (a);

and have b be set to some number representing the size of a in bytes, but
I cannot refer to the same structure from another source file:

	  ...

	extern struct a[];

	  ...

	b = sizeof (a);		/* set to zero or a compiler error msg */

The array is defined and initialized to contain data.  Therefore, the
sizeof operator should work *regardless* of what source file it is used in.

			robert
-- 
Robert Viduya
    Office of Computing Services
    Georgia Institute of Technology, Atlanta GA 30332
    Phone:  (404) 894-4669

...!{akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp}!gatech!gitpyr!robert
...!{rlgvax,sb1,uf-cgrl,unmvax,ut-sally}!gatech!gitpyr!robert



More information about the Comp.lang.c mailing list