Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller <sha0.miller@xxxxxxxxx>
- Date: Wed, 11 Aug 2010 13:53:28 -0700 (PDT)
On Aug 11, 4:14 pm, Keith Thompson <ks...@xxxxxxx> wrote:
Shao Miller <sha0.mil...@xxxxxxxxx> writes:That makes complete sense. Essentially, "If an initializer appears
On Aug 10, 12:16 pm, Keith Thompson <ks...@xxxxxxx> wrote:
Shao Miller <sha0.mil...@xxxxxxxxx> writes:
[...]> I suppose it just seems counter-intuitive to me that function
arguments be treated the same as sub-expressions for the computation
of a single value, instead of as independent expressions not part of a
larger expression.
[...]
A function call is an expression (6.5.2.2).Yes of course, and that is why I've conceded.
So how about:
int a = 1;
printf("%d", (int){ ++a }, (int){ a + 5 });
? There appear to be 3 full expressions in the second line, there.
Does 6.5p2 apply there, too?
Hmm. (int){ ++a } and (int){ a + 5 } are compound literals.
The syntax of a compound literal is:
( type-name ) { initializer-list }
( type-name ) { initializer-list , }
Following the syntax of initializer-list, we see that ++a and a + 5 are
both initializers. 6.8p4 seems to say that both that an initializer is
a full expression, and that these particular initializers are not.
Here's the full paragraph:
A _full expression_ is an expression that is not part of another
expression or of a declarator. Each of the following is a full
expression: an initializer; the expression in an expression
statement; the controlling expression of a selection statement
(if or switch); the controlling expression of a while or do
statement; each of the (optional) expressions of a for statement;
the (optional) expression in a return statement. The end of a
full expression is a sequence point.
The first sentence is the definition of the term "full expression".
By this definition, since ++a and a + 5 are part of larger
expressions, they clearly aren't full expressions. But the next
sentence says that an initializer is a full expression.
The wording is unchanged, or nearly so, from C90, which didn't
have compound literals; initializers appeared only in declarations.
I suggest that the authors neglected to update this paragraph when
compound literals were added, and that these initializers are not
(or should not be) considered to be full expressions; thus the
behavior is undefined.
within an expression, it is not a full expression."
.
- Follow-Ups:
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- References:
- C Test Incorrectly Uses printf() - Please Confirm
- From: Martin O'Brien
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: pete
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: pete
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: pete
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Keith Thompson
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Keith Thompson
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Shao Miller
- Re: C Test Incorrectly Uses printf() - Please Confirm
- From: Keith Thompson
- C Test Incorrectly Uses printf() - Please Confirm
- Prev by Date: Re: C vs. Fortran (half OT questions)
- Next by Date: Re: C vs. Fortran (half OT questions)
- Previous by thread: Re: C Test Incorrectly Uses printf() - Please Confirm
- Next by thread: Re: C Test Incorrectly Uses printf() - Please Confirm
- Index(es):
Relevant Pages
|