Date: Mon, 19 Feb 2001 22:33:58 +1100 (EST) From: Bruce Evans <bde@zeta.org.au> To: Peter Wemm <peter@netplex.com.au> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.sbin/config Makefile config.h config.y lang.l main.c mkmakefile.c mkoptions.c Message-ID: <Pine.BSF.4.21.0102192054570.11651-100000@besplex.bde.org> In-Reply-To: <200102190458.f1J4wfr53235@mobile.wemm.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 18 Feb 2001, Peter Wemm wrote: > Peter Wemm wrote: > > peter 2001/02/18 20:43:22 PST > > > > Modified files: > > usr.sbin/config Makefile config.h config.y lang.l main.c > > mkmakefile.c mkoptions.c > > Log: > > ${BDECFLAGS} work. And fix a real error in the process. A "MAXUSERS" > > string could have been passed to free(); There are some warnings here > > I am not sure how to fix as they are in the lex scanner code, etc. > > And this one really takes the cake: > main.c:140: warning: passing arg 2 of `mkdir' with different width due to prototype > > The line is: mkdir(p, 0777); > The prototype is: mkdir(const char *, mode_t); > The type of mode_t is u_int16_t. > > However, mkdir(p, (mode_t)0777); does not fix the warning. I seem to recall > the i386 ABI promoting everything to 32 bit first and suspect that there > is some gcc strangeness with the 16 bit arg and the 32 bit promotion.. The warning option that gives this (-Wconversion) is mainly for K&R compatibility/portability. A more complete message would say: main.c:140: warning: passing arg 2 of `mkdir' with a possibly different \ width than would be passed if a prototype were not \ in scope In other words, it says that the call to mkdir() might not work on all target machines if a prototype were not in scope. It intentionally doesn't say that there is no problem on the current (i386) target machine because it is about portability. Since a prototype should always be in scope if possible, the warning only helps to predict problems when it is impossible, i.e., mainly for compiling with a K&R compiler. mkdir(p, (mode_t)0777); does not "fix" the warning because it (mode_t)0777 has type u_short on i386's, so it would be promoted to int (u_int for K&R compilers) if a prototype were not in scope (this promotion is required by the K&R "spec" and the ISO spec). When a prototype is in scope, the arg is demoted to u_short for passing. u_short != int, so the warning is printed. However, the ABI requires passing u_shorts as ints so the arg gets promoted again. mknod() in the kernel is bogusly declared as taking an int so it depends on the last promotion. If it were correctly declared then it would have to demote the int back to a u_short again. Some of these conversions have unavoidable runtime costs. The "right" fix for this is to not use types shorter than ints in APIs. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0102192054570.11651-100000>