While trying to compile libskey with various warnings enabled, I
discovered the following funny thing about -Wconversion and umask(2),
which caused libskey to fail to compile, because it compiles by default
with -Werror which makes every warning fatal.
I found that the warning is caused when a program that calls umask(2) is
compiled with -Wconversion. The info page of gcc says about -Wconversion:
`-Wconversion'
Warn if a prototype causes a type conversion that is different
from what would happen to the same argument in the absence of a
prototype. This includes conversions of fixed point to floating
and vice versa, and conversions changing the width or signedness
of a fixed point argument except when the same as the default
promotion.
Also, warn if a negative integer constant expression is implicitly
converted to an unsigned type. For example, warn about the
assignment `x = -1' if `x' is unsigned. But do not warn about
explicit casts like `(unsigned) -1'.
The following test program when compiled with -Wconversion shown below
will always give a warning, even if I explicitly try to cast the
argument of umask() to mode_t.
1 #include <stdio.h>
2 #include <sys/stat.h>
3
4 int main (void)
5 {
6 mode_t oldmask;
7
8 oldmask = umask(0);
9 printf("The umask has changed\n");
10 umask(oldmask);
11 return 0;
12 }
The output given when I compile this with -Wconversion is:
gray-charon:/home/charon/test% gcc -Wconversion test.c -o test
test.c: In function `main':
test.c:8: warning: passing arg 1 of `umask' with different width due to prototype
test.c:10: warning: passing arg 1 of `umask' with different width due to prototype
The problem is that even if I change line 8 to read:
8 oldmask = umask((mode_t) 0);
the warning is still there. Am I being a bit too strict with all these
warnings here? If not, does anyone else have any idea why umask(2) will
always cause such a warning, and how I can go about correcting it?
Casting obviously fails, so something else needs to be done.
--
Giorgos Keramidas, <[EMAIL PROTECTED]>
For my public pgp2 key: finger -l [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message