hiding lint's ravings (was Re: FAQ - malloc array - clarify)

James Darrell McCauley jdm5548 at diamond.tamu.edu
Sun Sep 9 03:45:06 AEST 1990


How do you professionals deal with insignificant(?) ravings from
lint (or other high quality C program verifiers) such as the 
following:

>test.c(x): warning: possible pointer alignment problem
which was caused by the malloc in:

>double **dmatrix(nr,nc)
>int nr,nc;
>{
>  double **m = NULL;
>
>  m = (double **) malloc( (unsigned) nr * sizeof(double *) );
>  if (!m) ...

>From what netlanders tell me, this warning is explanined as:
(by Conor P. Cahill) 
|>                         The problem is that malloc is defined
|> as returning a pointer to char which has looser alignment requirements than
|> pointer to pointer.  Since malloc guarrantees that the result is suitably 
|> alligned for all data types, you can ignore this message.

Well, I can just ignore warnings like this, but those who review
my code (professors, employers, clients) are not likely to. It makes
an bad impression and frankly, I find it a little embarrassing.
(I'm embarrassed for those who publish code in which lint detects
things like unused arguments, etc). I could just:
#ifndef lint
   m = (double *) malloc(...
#endif
but before long, the code looks disgusting.  Do you just ignore
warnings like this and remain confident in your code, or do you
do your best to work around them?

By the way, I got this error while using a Sparc under Sun OS 4.0.3c,
but not under 4.0.3 (which perplexes me).
--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James Darrell McCauley                 jdm5548 at diamond.tamu.edu
Dept of Ag. Engineering                          (409) 845-6484
Texas A&M University, College Station, Texas 77843-2117, USA
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



More information about the Comp.unix.programmer mailing list