Determing alignment of (char *) pointer

Henry Spencer henry at utzoo.UUCP
Sun Dec 7 11:45:38 AEST 1986


> 	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...

Also on some non-broken compilers, alas.  Converting "char *" to "long *"
with a cast does not guarantee that the result is a VALID "long *".  That
is your problem, not the compiler's.  On some machines this will work,
because the conversion involves a change in representation, explicitly
dropping the higher-precision part of the char pointer.  But on orthodox
machines like VAXen and 68Ks, the compiler makes no attempt to clear those
nasty low-order bits, so the comparison tells you nothing.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,decvax,pyramid}!utzoo!henry



More information about the Comp.lang.c mailing list