🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #106

Re: Aligning an arbitrary pointer?

#106
From: John F. Woods
Date: Tue, 21 Jul 1992 16:08
17 lines
1546 bytes
flaps@dgp.toronto.edu (Alan J Rosenthal) writes:
[ make a union of everything and use its size as the magic pessimal alignment
 constant ]
>The existence of this constant is the remaining issue.  I don't think that
>anything in the standard mandates that this exists; for example, suppose the
>rule was that all pointers, ints, longs, etc had to be aligned on an *odd*
>word?  But I'd be awfully surprised if such a machine existed.

I *think* that the standard requires alignment to get worse, so that odd word
alignment wouldn't be legal, but I'm not sure.  However, there's still a
fundamental problem -- in order to round up a random pointer in this manner,
you need to perform integer arithmetic on it, not pointer arithmetic.  The
standard makes too few guarantees about what happens when you turn pointers
into integers and vice versa.  If you have an array of char whose base you
*know* is maximally aligned (eg it came from malloc (the title of a horror
film?)), then you can re-align pointers within the array if you have the
base pointer handy.
Technical Details
Message-ID: <14005@ksr.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!mips!pacbell.com!decwrl!world!ksr!jfw
References: <PDS.92Jul16111642@lemming.webo.dg.com> <1473f4INNq24@early-bird.think.com> <PDS.92Jul18154500@lemming.webo.dg.com> <1992Jul20.152052.329@jarvis.csri.toronto.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!mips!pacbell.com!decwrl!world!ksr!jfw
From: jfw@ksr.com (John F. Woods)
Newsgroups: comp.std.c
Subject: Re: Aligning an arbitrary pointer?
Message-ID: <14005@ksr.com>
Date: 21 Jul 92 12:08:18 EDT
References: <PDS.92Jul16111642@lemming.webo.dg.com> <1473f4INNq24@early-bird.think.com> <PDS.92Jul18154500@lemming.webo.dg.com> <1992Jul20.152052.329@jarvis.csri.toronto.edu>
Sender: news@ksr.com
Lines: 17