[net.lang.c] What's wrong with printf

lvc@danews.UUCP (Larry Cipriani) (05/11/86)

> What's wrong with
> 	printf("usage: foo bar\n"), exit(1);
> as above?
> 

Aside from style, exit is a statement syntatically but , requires
expressions.  The compilers I've used will accept this and do
what you'd expect.  Why is that ?  Is this a special exeption ?

Compilers may exist that won't accept it.  However, this:

	printf("uage: foo bar\n"), return 1 ;

generates a syntactic error message.  If a compiler accepts , exit()
why not , return ?  Maybe it's too complicated to do, and not worth the
trouble.

Some uses of , are transparent and useful.  Such as multiple initial-
izations in a for loop, e.g. for(i = 0 , j = 1; ...).  Doing all the
relevant initializations in one place is important.  Or in a while loop:

	while(readresp(CMD), command)

where readresp is a void function (and has to be) and command is side
affected several routines down.  Coding this without the , obscures the
code (at least to me).

-- 

Larry Cipriani		Nothing is worse than having
danews!lvc		an itch you can never scratch

lvc@danews.UUCP (Larry Cipriani) (05/11/86)

I wrote:
>> What's wrong with
>> 	printf("usage: foo bar\n"), exit(1);
>> as above?
>> 

>Aside from style, exit is a statement syntatically but , requires
>expressions.  The compilers I've used will accept this and do
>what you'd expect.  Why is that ?  Is this a special exeption ?

Oops.  I mistakenly believed exit and return were both reserved words
in C but only return is.  There may be compilers that won't accept it
but they would be wrong.

	printf("usage: foo bar\n") , return 1 ;

seems reasonably "within C's style".  Comments ?
-- 

Larry Cipriani		Nothing is worse than having
danews!lvc		an itch you can never scratch

ark@alice.UucP (Andrew Koenig) (05/17/86)

> Oops.  I mistakenly believed exit and return were both reserved words
> in C but only return is.  There may be compilers that won't accept it
> but they would be wrong.
>
>	printf("usage: foo bar\n") , return 1 ;
>
> seems reasonably "within C's style".  Comments ?

return isn't an expression.  You can't write

	printf("usage: foo bar\n") , if (!fflag) exit(1);

either.

lvc@danews.UUCP (Larry Cipriani) (05/19/86)

> > Oops.  I mistakenly believed exit and return were both reserved words
> > in C but only return is.  There may be compilers that won't accept it
> > but they would be wrong.
> >
> >	printf("usage: foo bar\n") , return 1 ;
> >
> > seems reasonably "within C's style".  Comments ?

> return isn't an expression.  You can't write

> 	printf("usage: foo bar\n") , if (!fflag) exit(1);

> either.

I knew that return wasn't an expression.  The fact that you can
do `control flow' with , seperating expressions makes me wonder
why this wasn't extended to include 'some' statements such as return.

Thanks,

-- 

Larry Cipriani		AT&T Network Systems
cbsck!lvc	Mail responses to ihnp4!cbsck!lvc please - thanks

kwh@bentley.UUCP (KW Heuer) (05/23/86)

In article <123@danews.UUCP> danews!lvc writes:
>I knew that return wasn't an expression.  The fact that you can
>do `control flow' with , seperating expressions makes me wonder
>why this wasn't extended to include 'some' statements such as return.

It makes about as much sense as "printf() + return".  Comma in this context
is an *operator*.  A more serious argument would be to allow the statement
"return ((void)printf())", which would make sense if "void" were a real
datatype.

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint