Order of evaluation and better declaration of functions

  • Thread starter Bhushit Joshipura
  • Start date
R

Ron Natalie

Jerry Coffin said:
It's not required because nothing in the
standard requires it.

Actually, the omission of a defined behavior in the standard is UNDEFINED
BEHAVIOR. The ordering of operations is specifically stated as being arbitrary.
 
J

Jerry Coffin

Actually, the omission of a defined behavior in the standard is UNDEFINED
BEHAVIOR. The ordering of operations is specifically stated as being arbitrary.

Perhaps you should have actually read what I said -- I said that the
order of evaluation of subexpressions is unspecified. If you want that
more exactly, the C standard says (6.5/3):

Except as specified later (for the function call (), &&, ||, ?:
and comma operators), the order of evaluation of subexpressions
and the order in which side effect take place are both
unspecified.

The bit you've quoted above was referring specifically to whether there
was a requirement for an implementation to issue a diagnostic when the
output depends upon unspecified behavior. As I said, the answer is no,
and the reason is because no part of the standard requires a diagnostic.

The omission of behavior leading to undefined behavior ONLY relates to
the behavior the program at run time, NOT to behavior during
translation. The requirement for diagnostics is (5.1.1.3/1):

A conforming implementation shall produce at least one diagnostic
message (identified in an implementation defined manner) if a
preprocessing translation unit or translation unit contains a
violation of any syntax rule or constraint, even if the behavior
is also explicitly specified as undefined or implementation-
defined. Diagnostic messages need not be produced in other
circumstances.


Therefore, (as I said before) a diagnostic is not required because
nothing says it is -- i.e. there is no constraint (and clearly no syntax
rule) that says the output of a program cannot depend upon unspecified
behavior. Therefore, this is one of those "other circumstances" in
which a diagnostic need not be produced.
 
P

Peter Nilsson

Christopher Benson-Manica said:
Oh, I see. Right. Well, even if a compiler can't find *every*
instance of OOE code, mightn't it still be nice to require a
diagnostic for

j=++i+++i;

That expression does require a diagnostic. ;)
 
O

Old Wolf

Oh, I see. Right. Well, even if a compiler can't find *every*
instance of OOE code, mightn't it still be nice to require a
diagnostic for

j=++i+++i;

?

Error: invalid lvalue in increment
 
D

David Harmon

Therefore, (as I said before) a diagnostic is not required because
nothing says it is

That's exactly correct, but not terribly informative. I'm think the
poster asking "why not" would like to know why the standard doesn't
require it. http://www.netfunny.com/rhf/jokes/98/Aug/sales.html

For one reason, because the standard generally requires a diagnostic
only for programs that are ill-formed, and this isn't.

For another, because it's unreasonable to expect the compiler to be able
to figure it out. Should a nuisance warning be produced for
int i = f() + g();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,137
Messages
2,570,797
Members
47,342
Latest member
eixataze

Latest Threads

Top