tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: __attribute__((warn_unused_result)) for NetBSD?



> Warnings that are too verbose on perfectly good code are actually of
> negative value, because they conceal "real" warnings.  The question is
> whether something like

>       printf("done\n");

> is "perfectly good code", or whether it needs to be cast to void to
> qualify.

I also don't see reasons to checks return value printf. No problem.

> Of course, the compiler is free to warn about anything it feels like
> ("warning: your indentation style is inconsistent", "warning: your
> variable names are confusingly similar").  But one which produces too
> many warnings about non-problems will provoke the above effect, hiding
> warnings about real problems amid useless noise.
JFYI: M$ C/C++ compiler as well as Intel compiler allow
to enable/disable/make_error every individual warning.
All warnings are numbered for this purpose.
Unfortunately gcc cannot do this (AFAIK).

> The functions which I think deserve the marking are functions with no
> side effects (abs, atof, atoi, atol, feof, etc)
Ok. Such functions are from category #1 "no side effects".
I have nothing against it.

> and a few functions
> which, while they have side effects, have side effects that I cannot
> see any use for without the return value (fopen, malloc, etc).

 >> write, read, fwrite, fread...?

> None of those qualify, IMO, though read and fread come close.
Why? IMO Not checking for return value of all these functions as well
as close fclose etc. is VERY dangerous.

> Don't mistake me.  I think that routinely checking the return values of
> functions like write() and chdir() is good.  I just think demanding
> _always_ checking them is going too far.

I didn't suggest to ALWAYS produce such warnings.
BSD make's mk scripts supports WARNS variable.
This is how things may work.

Another example. In glibc-2.7 internal macro _FORTIFY_SOURCE
is used to enable WUR. By default WUR is disabled.
-Werror is also tunable.


In ALT Linux it works like this (4.0 Server (Walnut)).

0 ~>cat main.c
#include <unistd.h>

int main ()
{
  char c;
  read (0, &c, 1);
  return 0;
}

0 ~>gcc main.c

0 ~>gcc -O2 main.c
main.c: In function 'main':
main.c:6: warning: ignoring return value of 'read', declared with attribute 
warn_unused_result

0 ~>

-- 
Best regards, Aleksey Cheusov.


Home | Main Index | Thread Index | Old Index