Dead functions and /*NOTREACHED*/

Guy Harris guy at sun.uucp
Fri Sep 5 02:37:29 AEST 1986


> >While I'm at it, a similar comment could be added to tell lint that
> >a function like malloc or calloc always returns an aligned pointer.
> 
> Perhaps.

*Some* way to tell lint to shut the @#!!%%#@ up about pointer alignment
problems, even if the most stringent checking is enabled, is required;
complaints about "possible pointer alignment problems" when "malloc" is used
are pure noise.

> >I understand that ANSI C has a different solution for this,
> 
> No.  "void *" has nothing to do with guaranteed alignment, it just means
> "pointer to unknown".

ANSI C doesn't seem to have much to say about pointer alignment in general -
at least I couldn't find anything about it in the obvious places suggested
by the index (this may be a bug in the index).  However, nothing prevents a
compiler or "lint" from treating *all* "void *" pointers as always being
properly aligned; the most common uses of "void *" are 1) as the result of a
storage-allocation function - in this case, it can be assumed that the
function is returning something properly aligned, and 2) as an "opaque
pointer", used when a data structure is used to refer to objects of several
different types (and the set of object types cannot be determined when the
code is written, so a union can't be used) - in this case, the compiler
can't do the checking properly anyway, so warnings are largely useless.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list