Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!gatech!hubcap!ncrcae!ncr-sd!sagpd1!jharkins From: jharkins@sagpd1.UUCP (Jim Harkins) Newsgroups: comp.lang.c Subject: absolute variable positioning Keywords: hardware constraints Message-ID: <471@sagpd1.UUCP> Date: 7 Sep 89 22:54:10 GMT Organization: Scientific Atlanta-GPD, San Diego Lines: 30 Due to some hardware considerations I have a special block of memory that I have to use for storage of some variables. Lets say it starts at address FOO. In C, whats the best way to say "integer fred in normal mem, struct wilma somewhere after FOO, struct barney somewhere after FOO, struct bam_bam in normal mem", etc? The best I can come up with is pointer = FOO struct a *wilma = pointer pointer += sizeof(struct a) struct b *barney = pointer pointer += sizeof(struct b) * NUMBER_OF_BARNEYS /* array of barneys */ etc etc Needless to say, this seems somewhat cumbersome and prone to error. Especially to the poor sucker that has to maintain the code. To try to cut down on the number of well-meaning but frivolous responces: 1. If I made a stupid mistake in this message, assume I know what I'm doing and I made a typo. (I seem to get more responces from typos than anything). 2. If I have to resort to the scheme above I'll encapsulate it in a function. 3. So far I haven't needed to de-allocate variables once allocated, and they all get allocated on power up. But this may change... 4. I don't have a malloc available to do this unless I write one myself. (I know, one's in K&R). Jim "Only dead fish go with the flow"