Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!tikal!sigma!uw-nsr!uw-warp!cjsa!jeff From: jeff@cjsa.WA.COM (Jeffery Small) Newsgroups: comp.lang.c Subject: lint warning messages with malloc() Message-ID: <142@cjsa.WA.COM> Date: 2 Nov 88 18:56:47 GMT Organization: C. Jeffery Small and Associates - Woodinville, WA Lines: 56 When compiling a program on an AT&T 3B1 (running SystemV.2 +/-), I am getting the following warning message from lint when I use malloc(3): warning: possible pointer alignment problem Here is some sample code to illustrate the problem: ------- cut here ------------------------------------------------------- #define NULL 0 typedef struct { unsigned int x; unsigned int y; unsigned char *z; } X; main() { X *getptr(); if ( getptr() == (X *) NULL) return (1); else return(0); /*NOTREACHED*/ } X *getptr() { char *malloc(); return( (X *) malloc(sizeof(X)) ); /* WARNING FOR THIS LINE */ } ------ end ----------------------------------------------------------- Now, since the man page for malloc reads: Malloc returns a pointer to a block of at least size bytes suitably aligned for any use. I assume that lint is complaining not about the pointer returned from malloc(), but instead, about the alignment of the *z pointer which is a member of the structure. The program works on this machine, and while I know that lint is warning about a portability problem to other architectures, I do not know what I need to do to satisfy lint. Is some manual padding required within the structure, and if so, what are the rules for this. BTW, I have tried a number of different arrangements of the structure members with no satisfactory results. Thanks for any pointers. (Yea, I know :-) -- Jeffery Small (206) 485-5596 uw-beaver!uw-nsr!uw-warp C. Jeffery Small and Associates !cjsa!jeff 19112 152nd Ave NE - Woodinville, WA 98072 uunet!nwnexus