home *** CD-ROM | disk | FTP | other *** search
- Path: 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
-
- 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.
-