🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #120

Re: Aligning an arbitrary pointer?

#120
From: Alan J Rosenthal
Date: Sat, 25 Jul 1992 19:56
18 lines
1529 bytes
pds@lemming.webo.dg.com (Paul D. Smith) writes:
>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
...
>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! :-)

One common reason for dropping the additional accuracy is when the pointers are
actually of different format, so that the pointer-to-int cannot represent the
finer-grained pointing.  For example, the machine may be word-addressed, so
that (say) only every four eight-bit-bytes does the address go up by one (so
like the pointers to adjacent ints will have adjacent internal values).
Then a pointer-to-char may be larger than a pointer-to-int and contain the
pointer-to-int's information plus a number which is 0, 1, 2, or 3.  A cast from
pointer-to-char to pointer-to-int would simply have to throw away this second
number.
Technical Details
Message-ID: <1992Jul25.155641.22523@jarvis.csri.toronto.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!dgp.toronto.edu!flaps
References: <PDS.92Jul16111642@lemming.webo.dg.com> <1473f4INNq24@early-bird.think.com> <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!utcsri!dgp.toronto.edu!flaps
Newsgroups: comp.std.c
From: flaps@dgp.toronto.edu (Alan J Rosenthal)
Subject: Re: Aligning an arbitrary pointer?
Message-ID: <1992Jul25.155641.22523@jarvis.csri.toronto.edu>
References: <PDS.92Jul16111642@lemming.webo.dg.com> <1473f4INNq24@early-bird.think.com> <PDS.92Jul18154500@lemming.webo.dg.com> <14f6u9INNon7@early-bird.think.com> <PDS.92Jul21153918@lemming.webo.dg.com>
Date: 25 Jul 92 19:56:42 GMT
Lines: 18