Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!killer!convex!uunet!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.lang.c Subject: Re: Suitably aligned pointers Message-ID: <7675@boring.cwi.nl> Date: 22 Oct 88 16:45:40 GMT References: <345@marob.MASA.COM> <8810151524.AA16480@explorer.dgp.toronto.edu> Organization: CWI, Amsterdam Lines: 19 In article <8810151524.AA16480@explorer.dgp.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes: > > In article <345@marob.MASA.COM> daveh@marob.UUCP (Dave Hammond) writes: > >Can someone explain the technique used to suitably align a pointer ? > > Well, it can't be done very nicely in a portable way. It can be done very > easily in a machine-dependent way: just do this: > if ((long)p & 1) > p++; > for example to enforce even alignment. It is carefully mentioned that this is machine dependent, but not for what machines. This will fail on some. On at least one machine, to get even byte alignment, it suffices to do: p = (char *)(int *)p; (Yes, it uses different formats for char* and int*.) -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax