Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!brl-smoke!smoke!chris@mimsy.umd.edu From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: net.lang.c Subject: Re: char vs. int in arg decls Message-ID: <3877@brl-smoke.ARPA> Date: Tue, 16-Sep-86 16:07:05 EDT Article-I.D.: brl-smok.3877 Posted: Tue Sep 16 16:07:05 1986 Date-Received: Sat, 20-Sep-86 00:31:15 EDT Sender: news@brl-smoke.ARPA Lines: 52 From: Rick Genter Yes, it will work to interchange (int) and (char) as the types of function arguments, as long as you *never* use &, or *only* work on VAXen (and similar-endian machines). It will work at other times as well. I tried to port [code like the below] to the Sun. add_char_to_line (':'); /* draw border */ add_char_to_line (c) { /* no decl for c, so default to int */ <...> ins_char_in_buffer (& c, & buf); } ins_char_in_buffer (cp, bufp) char *cp; BUF *bufp; { <...> } This code is wrong, and lint will say so. It is wrong not because ':' is an int, and add_char_to_line's parameter is therefore int, but because add_char_to_line's parameter is declared as an int and its address (type `int *') is passed to a function expecting type `char *'. Were add_char_to_line declared as add_char_to_line(c) char c; { ... ins_char_in_buffer(&c, &buf); } the code would have been correct (even though the call to add_char_to_line above passes ':', which has type `int': this is another place where automatic promotion has odd effects). Dennis would have liked this guy; I said "lint" to him and he replied "?" :-). Actually, I believe `?' is due to Kernighan. (Anyone at You Know Where care to comment?) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu