From owner-freebsd-hackers Tue Nov 7 2: 5:58 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from gray.westgate.gr (gray.westgate.gr [212.205.119.66]) by hub.freebsd.org (Postfix) with ESMTP id F058337B4CF for ; Tue, 7 Nov 2000 02:05:51 -0800 (PST) Received: (from charon@localhost) by gray.westgate.gr (8.11.1/8.11.1) id eA7A5B198116 for hackers@freebsd.org; Tue, 7 Nov 2000 12:05:11 +0200 (EET) Date: Tue, 7 Nov 2000 12:05:11 +0200 From: Giorgos Keramidas To: hackers@freebsd.org Subject: umask(2) and -Wconversion Message-ID: <20001107120511.A98074@gray.westgate.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-PGP-Fingerprint: 3A 75 52 EB F1 58 56 0D - C5 B8 21 B6 1B 5E 4A C2 X-URL: http://students.ceid.upatras.gr/~keramida/index.html Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 2 #include 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, For my public pgp2 key: finger -l keramida@diogenis.ceid.upatras.gr To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message