comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <chapinp@acm.org>
Subject: Re: YACT (Yet Another C Trap)
Date: Mon, 30 Aug 2010 06:13:50 -0400
Date: 2010-08-30T06:13:50-04:00	[thread overview]
Message-ID: <4c7b84a6$0$2375$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <Pine.LNX.4.64.1008301026390.28253@medsec1.medien.uni-weimar.de>

On 2010-08-30 04:28, stefan-lucks@see-the.signature wrote:

> P.S.: Even gcc -Wall doesn't warn about the flawed ",". It just tells me 
> "control reaches end of non-void function" (my main function should return 
> an integer, but it doesn't).

In the expression statement

	x = 12,3;

first 12 is assigned to x and then the expression '3' is evaluated, the
result of which is ignored. It has a similar effect to

	x = 12;
	3;

except that it is one statement instead of two. The key point here is
that the comma operator has lower precedence than even assignment. In C
a statement can just be an expression followed by a semicolon. Since it
is legal to write expressions that have no side effects you can do
things like

	a + b;

Given your original code ('x = 12,3') the Open Watcom C compiler issues
the warning, "Expression is only useful for its side effects." It's a
strange warning in some ways since the problem here is that the
expression in question ('3') has no side effects.

Ada avoids these problems because in Ada you can't just put a semicolon
at the end of an expression to make a statement (assignment isn't an
operator in Ada).

Peter



      reply	other threads:[~2010-08-30 10:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21  9:32 YACT (Yet Another C Trap) mockturtle
2010-08-27  4:13 ` Shark8
2010-08-29 20:55 ` Maciej Sobczak
2010-08-30  8:21   ` stefan-lucks
2010-08-30  7:52     ` Maciej Sobczak
2010-08-30  8:28     ` stefan-lucks
2010-08-30 10:13       ` Peter C. Chapin [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox