Determing alignment of (char *) pointer

Karl Heuer karl at haddock.UUCP
Wed Dec 10 13:43:30 AEST 1986


In article <1510 at mit-trillian.MIT.EDU> newman at athena.mit.edu (Ron Newman) writes:
>Which is a better, more portable way of determining whether a pointer
>[char *p] is aligned?

Several answers have been proposed, each of which fails on some machine.
I had this same situation a while back, and I solved it with the "most
portable" method:  "if (isaligned(p)) ...".  I then wrote the isaligned()
macro, and put it in a header file with a big comment.  Now the code works
on any machine, as long as I keep that header file up-to-date.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list