rgenter@labs-b.bbn.com (Rick Genter) (09/16/86)
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). At my previous employer we had a late-night hacker who had written a really nice screen editor. One day I tried to port it to the Sun. Nothing worked (core dumped before clearing the screen). I started to track it down, then noticed things like: <...> 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; { <...> } Needless to say, this kind of coding was sprinkled throughout the source. Dennis would have liked this guy; I said "lint" to him and he replied "?" :-). The moral of the story: say what you mean, even if it *usually* doesn't matter. -------- Rick Genter BBN Laboratories Inc. (617) 497-3848 10 Moulton St. 6/512 rgenter@labs-b.bbn.COM (Internet new) Cambridge, MA 02238 rgenter@bbn-labs-b.ARPA (Internet old) linus!rgenter%BBN-LABS-B.ARPA (UUCP)
chris@mimsy.umd.edu (Chris Torek) (09/16/86)
From: Rick Genter <rgenter@labs-b.bbn.com> 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