From owner-freebsd-bugs Thu Aug 27 20:39:33 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA10108 for freebsd-bugs-outgoing; Thu, 27 Aug 1998 20:39:33 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.15.68.22]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA10039 for ; Thu, 27 Aug 1998 20:39:08 -0700 (PDT) (envelope-from bde@godzilla.zeta.org.au) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.7/8.8.7) id NAA22459; Fri, 28 Aug 1998 13:38:11 +1000 Date: Fri, 28 Aug 1998 13:38:11 +1000 From: Bruce Evans Message-Id: <199808280338.NAA22459@godzilla.zeta.org.au> To: bde@zeta.org.au, jdp@polstra.com Subject: Re: error in libcompat (2.2.7) Cc: bugs@FreeBSD.ORG, dmm125@bellatlantic.net Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >> Not a bug. The prototype must declare the arg as an int to match the >> old-style-but-still-ANSI definition. The definition uses char for >> historical reasons. Changing it would be incompatible. See rev.1.4 >> of ftok.3 for some notes about this. > >I don't agree. If the prototype says it's an int, then it should be >declared as int in the definition too. The definition should look >like this: > >key_t >ftok(path, id) > const char *path; > int id; >{ > struct stat st; > > if (stat(path, &st) < 0) > return (key_t)-1; > > return (key_t) ((char)id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); >} > >Here, I changed the type of "id" to int, and added a (char) cast in >front of its only use. This is just doing the compiler's work for it. The `char id' arg in the definition causes the `int id' arg in the prototype to be converted to a char on entry to the function, as if by assignment (ISO 6.7.1). Your cast is equivalent to such an assignment, modulo compiler optimizations, compiler warnings (compilers tend to warn more about assignments than casts) and style bugs. Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message