tech-userlevel archive

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

Re: Proposal: remove usr.bin/mkstr

> Do you know of any C compiler that complains in a helpful way when
> someone calls isspace(char)?


The gcc that shipped with 5.2, run with -Werror -W -Wall
-Wpointer-arith -Wcast-qual -Wwrite-strings -Wstrict-prototypes
-Wmissing-prototypes -Wno-uninitialized -Wno-sign-compare
-Wno-missing-field-initializers -Wno-pointer-sign
-Wno-format-zero-length (probably not all necessary) does:

% cat z.c
#include <ctype.h>
extern int foo(char);
int foo(char x)
% wgcc -c z.c
z.c: In function 'foo':
"z.c", line 5: warning: array subscript has type 'char'

(wgcc is a script of mine that, as used there, runs gcc with those
options).  Could the warning be more explicit?  Probably.  But it is a
warning, and after running into one or two instances of it, it is
easily recognizable as being what it is.  It certainly is useful to me
in that it catches such mistakes when I make them.

As for your other challenges, I don't know.  I don't use bool, I don't
use getopt, and I have never tried anything like your strstr example,
so I am not competent to speak to those (the strstr one is really an
artifact of a botch in strstr's API, semi-compelled by C's design) -
though I have one remark on your bool item:

> Do you know of any C compiler that can treat bool as a separate data
> type from int, [...]

Any C compiler that implements C99 (or, presumably later) _must_ treat
_Bool[%] as a separate data type, because it has some very special:

       [#1] When any scalar value is converted to _Bool, the result
       is 0 if the value compares equal to 0; otherwise, the result
       is 1.

so "flag = 2" is, by definition, formally equivalent to "flag = 1" if
flag is a _Bool.  (This has no bearing on whether a warning is or isn't
produced; compilers may warn about anything they please.  Just that
_Bool _must_ be a separate data type.)

[%] Which is what bool is canonically typedeffed as when writing for a
    C version that has _Bool.

> Due to the above features, I'd say that lint is still useful.

I do not find it so.  In my experience, lint produces so many useless
warnings that it is mind-numbing to find the tiny signal hiding among
the barrage of noise - if indeed the signal is even there.  I find gcc
with the above list of warning options far more useful.  (It does
produce some noise, but little enough to be useful anyway.)

Perhaps this is an artifact of how I tend to code.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index