runtime 'sizeof()'?

Guy Harris guy at rlgvax.UUCP
Mon Jan 21 08:42:58 AEST 1985


> A third way, which I see to be the best, is to defer the evaluation of any
> sizeof operation that references an external value to link/load time and put
> a placeholder in its place.  The linker/loader would have to replace the
> placeholder with the actual size of the external variable (since it knows
> the size anyway).  This doesn't waste any unnecessary storage for 'hidden'
> variables and also allows using the sizeof operator with external variables.

Nice, except that there's a lot more to this than just giving the linker
the ability to do a "sizeof".

Take, for example,

	a = sizeof(b)*2 + 3;

If "b" were an "extern" array with an empty dimension specifier, so that
this constant would have to be evaluated at link time, the linker would
have to be able to perform arbitrary computations.  There are several
linkers which can do this (the DEC PDP-11 and VAX linkers among them),
but to make the UNIX linker handle this you'd not only have to add a
"sizeof" operator to the linker but add the ability to do this sort of
"complex relocation" as well.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list