Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site gitpyr.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!hao!hplabs!sdcrdcf!sdcsvax!akgua!gatech!gitpyr!robert From: robert@gitpyr.UUCP (Robert Viduya) Newsgroups: net.lang.c Subject: runtime 'sizeof()'? Message-ID: <33@gitpyr.UUCP> Date: Thu, 17-Jan-85 22:16:19 EST Article-I.D.: gitpyr.33 Posted: Thu Jan 17 22:16:19 1985 Date-Received: Mon, 21-Jan-85 04:35:54 EST Distribution: net Organization: Georgia Tech, Atlanta Lines: 41 [] The other day I was modifying some source code when I came across something that showed me one of the limitations of the sizeof operator. Basically, I had the following in a source file: extern struct s a[]; . . . b = sizeof(a); . . Needless to say, the compiler assigned 0 to b instead of the actual size of the array. Obviously, in order to handle things like this, C needs a runtime version of sizeof. I can see two ways of doing this. One way is to have the size of each variable stored as part of that variable (waste a bit of storage). Another way is to implement it as a real function that 'knows' where all the variables are and can compute the size of each (also can waste storage). 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. Comments anybody? 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