🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9333

Re: char vs. int in arg decls

#9333
From: Chris Torek
Date: Tue, 16 Sep 1986 20:07
52 lines
1944 bytes
	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
Technical Details
Message-ID: <3877@brl-smoke.ARPA>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!brl-adm!brl-smoke!smoke!chris@mimsy.umd.edu

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!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