gcc means lots of fun

On 6 Sep 2001 12:49:02 -0400, comeau@panix.com (Greg Comeau) wrote:

In article <> 3b9798ed.1617738@inn.qnx.com> >,
Bob Bottemiller <> bob.bottemiller@fmcti.com> > wrote:
Thanks a lot to Greg Comeau and Wojtech Lerch for their expert
commentary on the “a=b=c” type of C statement. Now, where would a
journeyman programmer go to learn more about the C standard and terms
like sequence points and arity. I work mainly from the K&R 2nd
edition ( (c) 1988 ) and Harbison and Steele’s “C, A Reference
Manual.”

Arity is a minor issue and deals with the number of arguments
to a function. You probably won’t see this discussed anywhere per se
(either by that term, or at all). But things like sequence points
should be in both the books that you mention above. In fact,
I seem to recall both books that you mention above each have
a chapter about expression evaluation issues (and so I would
expect would list “sequence point” in their respective index. No?

K&R (2nd ed.) has no entry for “sequence point” in its index (all the

farther I looked). But there is a relevant discussion in section 2.12
“Precedence and Order of Evaluation.”
Harbison and Steele’s book does indeed have two references to
“sequence point” in its index (where I didn’t look) and their comments
(pp. 74, 208) are a little more definitive. Example:
“A sequence point is a point in the program’s execution sequence at
which all previous side effects of execution are to have taken place
and at which no subsequent side effects will have occurred…”

Greg Comeau export ETA: Dec 1 10% “End of Summer” Offer
Comeau C/C++ ONLINE ==> > http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware’s Libraries… Have you tried it?

In article <3b9904fe.1141185@inn.qnx.com>,
Bob Bottemiller <bob.bottemiller@fmcti.com> wrote:

On 6 Sep 2001 12:49:02 -0400, > comeau@panix.com > (Greg Comeau) wrote:
In article <> 3b9798ed.1617738@inn.qnx.com> >,
Bob Bottemiller <> bob.bottemiller@fmcti.com> > wrote:
Thanks a lot to Greg Comeau and Wojtech Lerch for their expert
commentary on the “a=b=c” type of C statement. Now, where would a
journeyman programmer go to learn more about the C standard and terms
like sequence points and arity. I work mainly from the K&R 2nd
edition ( (c) 1988 ) and Harbison and Steele’s “C, A Reference
Manual.”

Arity is a minor issue and deals with the number of arguments
to a function. You probably won’t see this discussed anywhere per se
(either by that term, or at all). But things like sequence points
should be in both the books that you mention above. In fact,
I seem to recall both books that you mention above each have
a chapter about expression evaluation issues (and so I would
expect would list “sequence point” in their respective index. No?

K&R (2nd ed.) has no entry for “sequence point” in its index (all the
farther I looked). But there is a relevant discussion in section 2.12
“Precedence and Order of Evaluation.”

I’m surprised they have no index entry, but as you say they do cover
it, at least in part (I’m going from memory here).

Harbison and Steele’s book does indeed have two references to
“sequence point” in its index (where I didn’t look) and their comments
(pp. 74, 208) are a little more definitive. Example:
“A sequence point is a point in the program’s execution sequence at
which all previous side effects of execution are to have taken place
and at which no subsequent side effects will have occurred…”

Right, so if all previous side effects have occurred, then this
implies that the “state” of the “C machine” is known.

I’m being brief here, but sequence points in C include: ||, &&,
,(comma operator, not comma punctuator alone), just before a function
call is made (after it’s args are evaluated), at the end of a full
expression, and ?:. C++ adds some other scenarios.

Greg Comeau export ETA: Dec 1 10% “End of Summer” Offer
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware’s Libraries… Have you tried it?

Greg -
Sorry if my knowledge is out of date, as I learned C from the White Book
and C Puzzles, haven’t tried to write a compiler in a long time, and only
skimmed the articles about the update to ANSI C.
What is a “full expression”? Is it defined in the ANSI C by BNF or by
semantics? I remember you did make the point that in an assignment
expression the lvalue expression and the rvalue expression can be evaluated
in either/any order, and I understand that, and why it makes a difference.
But an assignment expression is an rvalue expression, as I recall, so all I
can think of as a “full expression” is one bounded by a semicolon on each
end with none contained within - in other words, a ( an
expression with its rvalue thrown away), at least in essence - is this
correct? Or have I missed something else?
I guess it’s a good thing I don’t write compilers, and I try not to
write code that has (hidden) side effects that depend upon order of
evaluation! :slight_smile:
Phil Olynyk

Greg Comeau wrote:

In article <> 3b9904fe.1141185@inn.qnx.com> >,
Bob Bottemiller <> bob.bottemiller@fmcti.com> > wrote:
On 6 Sep 2001 12:49:02 -0400, > comeau@panix.com > (Greg Comeau) wrote:
In article <> 3b9798ed.1617738@inn.qnx.com> >,
Bob Bottemiller <> bob.bottemiller@fmcti.com> > wrote:
Thanks a lot to Greg Comeau and Wojtech Lerch for their expert
commentary on the “a=b=c” type of C statement. Now, where would a
journeyman programmer go to learn more about the C standard and terms
like sequence points and arity. I work mainly from the K&R 2nd
edition ( (c) 1988 ) and Harbison and Steele’s “C, A Reference
Manual.”

Arity is a minor issue and deals with the number of arguments
to a function. You probably won’t see this discussed anywhere per se
(either by that term, or at all). But things like sequence points
should be in both the books that you mention above. In fact,
I seem to recall both books that you mention above each have
a chapter about expression evaluation issues (and so I would
expect would list “sequence point” in their respective index. No?

K&R (2nd ed.) has no entry for “sequence point” in its index (all the
farther I looked). But there is a relevant discussion in section 2.12
“Precedence and Order of Evaluation.”

I’m surprised they have no index entry, but as you say they do cover
it, at least in part (I’m going from memory here).

Harbison and Steele’s book does indeed have two references to
“sequence point” in its index (where I didn’t look) and their comments
(pp. 74, 208) are a little more definitive. Example:
“A sequence point is a point in the program’s execution sequence at
which all previous side effects of execution are to have taken place
and at which no subsequent side effects will have occurred…”

Right, so if all previous side effects have occurred, then this
implies that the “state” of the “C machine” is known.

I’m being brief here, but sequence points in C include: ||, &&,
,(comma operator, not comma punctuator alone), just before a function
call is made (after it’s args are evaluated), at the end of a full
expression, and ?:. C++ adds some other scenarios.

Greg Comeau export ETA: Dec 1 10% “End of Summer” Offer
Comeau C/C++ ONLINE ==> > http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware’s Libraries… Have you tried it?

Phil Olynyk <pholynyk@home.com> wrote:

What is a “full expression”? Is it defined in the ANSI C by BNF or by
semantics? I remember you did make the point that in an assignment
expression the lvalue expression and the rvalue expression can be evaluated
in either/any order, and I understand that, and why it makes a difference.

6.8 Statements and blocks

4 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.

\

Wojtek Lerch QNX Software Systems Ltd.

In article <3B9CCF22.48BC0E4@home.com>, Phil Olynyk <pholynyk@home.com> wrote:

What is a “full expression”? Is it defined in the ANSI C by BNF or by
semantics?

The “BNF” used by Standard C does not express a full grammar,
and so therefore is incomplete, and so therefore is made complete
by English prose. Furthermore ``full expression’’ is an explicitly
defined term in Standard C (I don’t have the formal definition handy).

I remember you did make the point that in an assignment
expression the lvalue expression and the rvalue expression can be evaluated
in either/any order, and I understand that, and why it makes a difference.
But an assignment expression is an rvalue expression, as I recall,

Ok.

so all I
can think of as a “full expression” is one bounded by a semicolon on each
end with none contained within - in other words, a ( an
expression with its rvalue thrown away), at least in essence - is this
correct? Or have I missed something else?

That’s one kind of full expression. There’s a bunch of others,
like an initializer, or the condition in an if statement, etc.

Greg Comeau export ETA: Dec 1 10% “End of Summer” Offer
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware’s Libraries… Have you tried it?

Thank you, Wojtek and Greg. I’m glad I was at least partially right :slight_smile: C is my
most important tool - aside from my brain.
I guess it’s time to get and read a good book about ANSI Standard C, and get more
up to date on details.

Phil

Greg Comeau wrote:

In article <> 3B9CCF22.48BC0E4@home.com> >, Phil Olynyk <> pholynyk@home.com> > wrote:
What is a “full expression”? Is it defined in the ANSI C by BNF or by
semantics?

The “BNF” used by Standard C does not express a full grammar,
and so therefore is incomplete, and so therefore is made complete
by English prose. Furthermore ``full expression’’ is an explicitly
defined term in Standard C (I don’t have the formal definition handy).

I remember you did make the point that in an assignment
expression the lvalue expression and the rvalue expression can be evaluated
in either/any order, and I understand that, and why it makes a difference.
But an assignment expression is an rvalue expression, as I recall,

Ok.

so all I
can think of as a “full expression” is one bounded by a semicolon on each
end with none contained within - in other words, a ( an
expression with its rvalue thrown away), at least in essence - is this
correct? Or have I missed something else?

That’s one kind of full expression. There’s a bunch of others,
like an initializer, or the condition in an if statement, etc.

Greg Comeau export ETA: Dec 1 10% “End of Summer” Offer
Comeau C/C++ ONLINE ==> > http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware’s Libraries… Have you tried it?