Pointer Alignment on Suns

Bill Edwards lloyd!wse at husc6.harvard.edu
Fri Aug 25 04:59:53 AEST 1989


Let's say I have a pointer to a 'struct foo' which I have typedef'ed to
FOOPTR.  If I then do something like:

	FOOPTR foo_ptr = (FOOPTR) malloc ((unsigned) sizeof (struct foo));

at the start of a function, lint on a Sun 4 (SPARC) complains that this
line has " possible pointer alignment problems" (lint does *not* give me
this meesage on a Sun 3).  I wrote a short program to do a sizeof of
'struct foo'.  On the Sun 3, 'struct foo' has a size which is not
divisible by 4, but on the Sun 4 its size *is* divisible by 4 (has
evidently been padded to a long-word boundary).  So, my question is, how
do I placate lint in this instance?  How do I align the pointer?  I've
tried ensuring that I only malloc memory in chunks in multiple of 4 sizes,
but to no avail.

Thanks. -- Bill Edwards
-- 
---------------------------------------------------------------------------
Bill Edwards                           wse%lloyd at husc6.harvard.edu (ARPA)
Camex;75 Kneeland St. Boston MA 02111  wse at lloyd.UUCP;edwards at harvunxw.bitnet
Tel.: (617) 426-3577                   Standard disclaimers



More information about the Comp.sys.sun mailing list