Article View: comp.std.c
Article #113Re: Aligning an arbitrary pointer?
From: Barry Margolin
Date: Thu, 23 Jul 1992 05:08
Date: Thu, 23 Jul 1992 05:08
35 lines
2120 bytes
2120 bytes
In article <PDS.92Jul21153918@lemming.webo.dg.com> pds@lemming.webo.dg.com (Paul D. Smith) writes:
> 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
I expect so as well. But since the purpose of my post was to list
useful possibilities, I didn't feel like mentioning all the other kinds of
systems. That's why I said "on some systems".
> 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.
I was wondering whether this was the case. I came up with an idea, but I'm
not sure whether it really works.
Declare the structure as a union, where one case is an array of page table
entries, and the other is the preceding stuff. Then find the array element
whose address is greater than the address of the end of the preceding
stuff. Use the address of that array element as the address of the page
table.
--
Barry Margolin
System Manager, Thinking Machines Corp.
barmar@think.com {uunet,harvard}!think!barmar
Technical Details
Message-ID:
<14les7INN4m@early-bird.think.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!barmarReferences:
<PDS.92Jul18154500@lemming.webo.dg.com> <14f6u9INNon7@early-bird.think.com> <PDS.92Jul21153918@lemming.webo.dg.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.std.c Subject: Re: Aligning an arbitrary pointer? Date: 23 Jul 1992 05:08:23 GMT Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 35 Message-ID: <14les7INN4m@early-bird.think.com> References: <PDS.92Jul18154500@lemming.webo.dg.com> <14f6u9INNon7@early-bird.think.com> <PDS.92Jul21153918@lemming.webo.dg.com> NNTP-Posting-Host: gandalf.think.com