Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!aplcen!ginosko!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: absolute variable positioning Keywords: hardware constraints Message-ID: <793@sdrc.UUCP> Date: 8 Sep 89 21:38:47 GMT References: <471@sagpd1.UUCP> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 31 In article <471@sagpd1.UUCP>, jharkins@sagpd1.UUCP (Jim Harkins) writes: > 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 */ I would suggest packaging all of the variables you want to be in the special memory into a single struct and then declaring a pointer to that struct that is initialized appropriately. struct special { struct a wilma; struct b barney; } *p = (struct special *)FOO; That solves the problem for static allocation, if you ever need dynamic allocation then you still have to write a malloc. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@SDRC.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 "I have plenty of good sense. I just choose to ignore it." -Calvin