Determing alignment of (char *) pointer

Wayne Throop throopw at dg_rtp.UUCP
Tue Dec 9 02:11:28 AEST 1986


> desj at brahms (David desJardins)
>   Why not use
>       if (p != (char *) (long *) p) ... ?
>    This should give you the relevant information (can a long be stored at
> the location pointed to by p?) without any machine dependencies.  I suppose
> on some (broken) compilers it might not work...

Well... no.  C casts don't guarantee to alter the alignment of pointers
to reflect architectural restrictions.  They just DON'T guarantee NOT to
do so.  Basically, there isn't any portable way of doing this.

--
A LISP programmer knows the value of everything, but the cost of nothing.
                                --- Alan J. Perlis
-- 
Wayne Throop      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.lang.c mailing list