Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!mit-eddie!mit-trillian!newman From: newman@mit-trillian.MIT.EDU (Ron Newman) Newsgroups: comp.lang.c Subject: Determing alignment of (char *) pointer Message-ID: <1510@mit-trillian.MIT.EDU> Date: Thu, 4-Dec-86 21:05:39 EST Article-I.D.: mit-tril.1510 Posted: Thu Dec 4 21:05:39 1986 Date-Received: Fri, 5-Dec-86 04:23:05 EST Reply-To: newman@athena.mit.edu (Ron Newman) Organization: MIT Project Athena Lines: 24 I am using a (char *) pointer to store a sequence of differently-typed and differently-sized objects. I want to make sure that each object will be properly aligned before storing it. In particular, I need to determine whether the pointer is 32-bit aligned before attempting to store a long by casting it to a (long *). Which is a better, more portable way of determining whether a pointer is aligned? char *p; /* method 1 */ if ((long)p & 3) ... /* method 2 */ if ((long)(p - (char *) 0) & 3) ... or if neither of these is best, what is better? /Ron Newman