Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Oct 1998 05:53:44 +0100 (MET)
From:      Luigi Rizzo <luigi@labinfo.iet.unipi.it>
To:        hackers@FreeBSD.ORG
Subject:   compiler prototype question...
Message-ID:  <199810290453.FAA07168@labinfo.iet.unipi.it>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810290453.FAA07168>