lint warning messages with malloc()

Tony Williams tonyw at microsoft.UUCP
Sat Nov 5 11:42:18 AEST 1988


In article <355 at marob.MASA.COM> daveh at marob.masa.com (Dave Hammond) writes:
|In article <142 at cjsa.WA.COM> jeff at cjsa.WA.COM (Jeffery Small) writes:
|>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
|>[...sample code deleted...]
|
|The program code is not at fault.  The problem is that lint does not
|know about malloc returning a suitably aligned pointer, therefore
|it complains.  You could do some fancy declaration footwork and declare
|
|X *malloc();

DO NOT DO THIS.  Since you are using lint, I assume you care somewhat
about portability :-).  There are machines out there for which
struct X * and char * have different representations.
On these machines, malloc will return the char* representation and you
must have the cast to convert it.

For the same reason, you must have a declaration
extern char* malloc();
in your programs, so that the compiler does not assume it is int.

I am afraid that we just have to live with some features of lint.
  Tony Williams



More information about the Comp.lang.c mailing list