From owner-freebsd-hackers Wed Oct 28 23:34:38 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id XAA15174 for freebsd-hackers-outgoing; Wed, 28 Oct 1998 23:34:38 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from labinfo.iet.unipi.it (labinfo.iet.unipi.it [131.114.9.5]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id XAA15169 for ; Wed, 28 Oct 1998 23:34:35 -0800 (PST) (envelope-from luigi@labinfo.iet.unipi.it) Received: from localhost (luigi@localhost) by labinfo.iet.unipi.it (8.6.5/8.6.5) id FAA07168; Thu, 29 Oct 1998 05:53:45 +0100 From: Luigi Rizzo Message-Id: <199810290453.FAA07168@labinfo.iet.unipi.it> Subject: compiler prototype question... To: hackers@FreeBSD.ORG Date: Thu, 29 Oct 1998 05:53:44 +0100 (MET) X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi, can someone tell me why in the following C program: int c1 (int c); int c1 (char c) { return 1 ; } Hi, can someone tell me why in the following C program: int c1 (int c); int c1 (char c) { return 1 ; } int c2 (int c); int c2 (c) char c; { return 1 ; } int c3 (char c); int c3 (c) int c; { return 1 ;} int c4 (char c); int c4 (int c) { return 1 ;} compiled on 2.2.6 produces this output: prova# cc -c -Wall proto.c proto.c:8: conflicting types for `c1' proto.c:7: previous declaration of `c1' proto.c: In function `c3': proto.c:14: argument `c' doesn't match prototype proto.c:13: prototype declaration proto.c: At top level: proto.c:17: conflicting types for `c4' proto.c:16: previous declaration of `c4' To me, c2() seems as bad as the others, and i don't understand why the compiler does not complain. It seems that when the prototype declares an "int" argument, then any signed/unsigned type is accepted for that argument in the non-ansi function body. As you can imagine this defeats the usefulness of prototypes and obfuscates code. Furthermore, with multiple arguments, i could even be suspicious of how the compiler behaves (e.g. does it push a wordsize argument and then tries to read it as multiple 1 or 2 byte items ?). and the reason i am asking on hackers... there is such code in the kernel, e.g. sys/i386/isa/if_ed.c function ed_get_packet() has this problem and i don't know if it a bug or what. cheers luigi -----------------------------+-------------------------------------- Luigi Rizzo | Dip. di Ingegneria dell'Informazione email: luigi@iet.unipi.it | Universita' di Pisa tel: +39-50-568533 | via Diotisalvi 2, 56126 PISA (Italy) fax: +39-50-568522 | http://www.iet.unipi.it/~luigi/ _____________________________|______________________________________ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message