[comp.lang.c] Lint warnings

karl@haddock.ISC.COM (Karl Heuer) (01/01/70)

In article <869@tjalk.cs.vu.nl> rblieva@cs.vu.nl (Roemer B. Lievaart) writes:
>In article <867@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP (der Mouse) writes:
>>Any warning should have a means to turn it off.  (For most current warnings,
>>which tend to be type clashes, this means is provided: it's called a cast.)
>
>Oh yeah? How about the message I get for EVERY casted malloc or realloc:
>:: somefile.c(007): warning: possible pointer alignment problem
>Can't shut lint up about that.

That's mostly true; there really should be a lintpragma for declaring aligned
pointers like the result of malloc().  A solution I've used in the past:
  #ifdef lint
  extern char *cmalloc();
  extern int  *imalloc();
  #else
  extern char *malloc();
  #define cmalloc(n) ((char *)malloc((n)*sizeof(char)))
  #define imalloc(n) ((int  *)malloc((n)*sizeof(int)))
  #endif

>BTW. Does anybody know how to stop lint complaining about functions
>returning values wich are always/sometimes ignored?  I get one for every
>time I use sprintf, fclose, strcpy and quite a few others!
>[ OK, I meant another way than indeed using the values.
>  I just don't need them (always)! ]

Explicitly cast them to (void).  If that's too much trouble, define a macro to
do it for you: "#define Strcpy(s,t) (void)strcpy(s,t)".  I recommend this only
for functions that return a useless value (like strcpy), not for those that
flag an error (like putchar).

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint