home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!sdd.hp.com!uakari.primate.wisc.edu!caen!uwm.edu!rpi!scott.skidmore.edu!psinntp!psinntp!dg-rtp!webo!dg-webo!pds
- From: pds@lemming.webo.dg.com (Paul D. Smith)
- Newsgroups: comp.std.c
- Subject: Re: Aligning an arbitrary pointer?
- Message-ID: <PDS.92Jul21153918@lemming.webo.dg.com>
- Date: 21 Jul 92 19:39:18 GMT
- References: <PDS.92Jul16111642@lemming.webo.dg.com>
- <1473f4INNq24@early-bird.think.com> <PDS.92Jul18154500@lemming.webo.dg.com>
- <14f6u9INNon7@early-bird.think.com>
- Sender: usenet@webo.dg.com (Usenet Administration)
- Organization: NSDD/ONSD, Data General Corp., Westboro, MA
- Lines: 49
- In-Reply-To: barmar@think.com's message of 20 Jul 1992 20:16:09 GMT
-
- [] Regarding Re: Aligning an arbitrary pointer?;
- [] barmar@think.com (Barry Margolin) writes:
-
- bm> In article <PDS.92Jul18154500@lemming.webo.dg.com>
- bm> pds@lemming.webo.dg.com (Paul D. Smith) writes:
-
- >I'm modifying an existing piece of code which allocates a huge
- >chunk of memory then segments it into various parts, one of which
- >is an array of structs (it's a page table).
-
- bm> On some systems, casting a pointer to a more restrictive type
- bm> may have the effect of realigning it. [...]
-
- Bleah :). Maybe true, but certainly not Standard practice. I would
- expect that on at least some systems the compiler will happily allow
- you to assign 0x01381 (or some other non-aligned value) to an int*,
- say, and then just core with a bus error (or otherwise die) when you
- tried to dereference the pointer (that's pretty much what happens on
- my RISC system :-)
-
- In fact I'd much rather it did that than quietly modify my pointer by
- dropping bits... it would be a *major* pain to find *that* bug! :-)
-
- >For various reasons I don't want to introduce massive changes;
- >the obvious way to do this properly is allocate the memory
- >individually so I know it's properly aligned, but I don't want to
- >change things that much. I can't think of *any* other way to do
- >it, actually.
-
- bm> Why not just declare a structure that contains the array and
- bm> the preceding stuff? The compiler will guarantee that the
- bm> array is suitably aligned.
-
- The preceding stuff is of dynamic size; it's read in from a file where
- the file contains the total size and interesting offsets. The page
- table size has to be dynamic as well.
-
- Anyway, I guess the consensus is that you can't do this in standard C,
- so that's all I wanted to know! Thanks all...
- --
-
- paul
- -----
- ------------------------------------------------------------------
- | Paul D. Smith | paul_smith@dg.com |
- | Data General Corp. | pds@lemming.webo.dg.com |
- | Network Systems Development Division | |
- | Open Network Systems Development | "Pretty Damn S..." |
- ------------------------------------------------------------------
-