[comp.lang.c] certain type mismatches

msb@sq.uucp (Mark Brader) (07/07/88)

Chris Torek (chris@mimsy.UUCP), no less, writes:

> > >		void execl(char *, ...);

> ... [if it returns at all] it only ever returns -1, so declaring it
> as `int' is somewhat pointless---the value is even less useful than
> that from, e.g., strcpy().

But "function returning int" and "function returning void" are different
types.  A compiler might choose to implement calls to these functions
differently.  For instance, it could require a function returning int
to push its return value on the stack, and leave the caller to pop it off.
Then if you declare the function type wrong, your stack is trashed.

There may be no such compilers at the moment, but they're certainly within
the rules.  int execl() and (void)execl(...); is what you must say.

Incidentally, the (January 1988) ANSI draft's requirement that void *
have the same representation as char * contains a similar defect.
Not only the representation but also the function calling conventions
applicable to the type should have been required to be the same.
I mentioned this in my public comment letter but, judging from the
response I received, I seem to have been misunderstood.

Mark Brader		"Strong typing isn't for weak minds; the argument
Toronto			'strong typing is for weak minds' is for weak minds."
utzoo!sq!msb, msb@sq.com					-- Guy Harris

chris@mimsy.UUCP (Chris Torek) (07/08/88)

In some article somewhere, I wrote:
>>... [execl] only ever returns -1, so declaring it as `int' is
>>somewhat pointless ...

In article <1988Jul7.141058.20804@sq.uucp> msb@sq.uucp (Mark Brader) remarks:
>But "function returning int" and "function returning void" are different
>types. ...  int execl() and (void)execl(...); is what you must say.

True enough.  What I had meant to imply, though, was that the
definition of execl() could well be changed.  This is not something
that applies to ANSI X3J11, but rather to IEEE P1003.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris