468,491 Members | 2,042 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

x = 0; x += ++x + x++; x == 4?

Hi,

is this result defined by the standard?

I'm just in a small "fight" with some workmates on this topic. So an
answer from more involved people could help.

Regards,
Christian
Feb 22 '08 #1
22 3779
Christian Johannes Charbula wrote:
is this result defined by the standard?
No. The second statement contains the expression in which the rules
are broken. See the Standard, [expr]/4.
I'm just in a small "fight" with some workmates on this topic. So an
answer from more involved people could help.
Never fight your workmates. It's detrimental to your career.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 22 '08 #2
Pete Becker schrieb:
A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.
Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

Regards,
Johannes

--
"PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
Rosenberg in dse <45**********************@newsspool3.arcor-online.net>
Feb 22 '08 #3
Johannes Bauer wrote:
Pete Becker schrieb:
>A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is
abominable.

Exactly, I fully second that. I do not understand at all why this
exact question comes up in this group (and in comp.lang.c, too, BTW)
every few days. Kind of annoying. You should think people have more
important problems.
Aw, those grown-ups and their "more important problems"! When
will they understand? <g>

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 22 '08 #4
Victor Bazarov schrieb:
>Exactly, I fully second that. I do not understand at all why this
exact question comes up in this group (and in comp.lang.c, too, BTW)
every few days. Kind of annoying. You should think people have more
important problems.

Aw, those grown-ups and their "more important problems"! When
will they understand? <g>
No, no, that's not how I meant it and from the grin I take it you
undertood me correctly. However, I believe that there are *dozens* of
really interesting, complex, real-world problems C++ provides - yet some
people get hung with totally arfificial problems which always boils down
to some definition in the standard - that's pretty boring :-)

Regards,
Johannes

--
"PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
Rosenberg in dse <45**********************@newsspool3.arcor-online.net>
Feb 22 '08 #5
Christian Johannes Charbula wrote:
is this result defined by the standard?
What result?

It's customary to write a complete question in the body of your post.
The subject line is only a short introduction to the contents of your
post, not the contents themselves. The post should be understandable
even without the subject line.
Feb 22 '08 #6
James Kanze wrote:
...
>Yes, but the original question was not about the "behavior", but about
the "result". While the OP didn't specify what exactly he meant by
"result" (probably the result of 'x == 4' expression), for many natural
interpretations of the term it is possible to come up with operator
definitions, which will produce a well defined "result" even though the
overall "behavior" is not specified.

It's possible,
That's exactly what I said. It is possible.
but anyone who overloads the given operators with
definitions so that such a result is guaranteed should be hung
and shot.
Considering that this discussion is centered around what essentially is
a basic C++ _puzzle_, not a piece of real-life code, the above statement
is utterly irrelevant.
With any reasonable overloading of the operators (for
a user defined type for which such operators would make sense),
the result is unspecified.
This statement is based on some undefinable ideas of what "reasonable".
I'm pretty sure one can come up with a "reasonable" overload with
perfectly specified results, although I don't see the point.

--
Best regards,
Andrey Tarasevich
Feb 22 '08 #7
On 2008-02-22 12:24:11 -0500, Johannes Bauer <df***********@gmx.desaid:
Pete Becker schrieb:
>A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.

Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.
It's called knowing your tools well. If you just don't know the
answer, then just say so or better yet just be quiet.

With a tool like C++ where you can write syntactically correct code but
with undefined behavior, it's good to know when you could be writing
such code or be reading such code from another programmer. And that is
exact what the OP asked: Is this code well-defined in C++?

Furthermore, the OP did not say this is production code. He did not
ask if this code is abominable or not. It is just an inquisition about
the rules of C++. So why shouldn't this question be raised in this
forum? Which forum should this post go where it won't be annoying?

--

// kira

Feb 22 '08 #8
On Feb 22, 5:12 pm, Kira Yamato <kira...@earthlink.netwrote:
On 2008-02-22 12:24:11 -0500, Johannes Bauer <dfnsonfsdu...@gmx.desaid:
Pete Becker schrieb:
A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.
Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the
answer, then just say so or better yet just be quiet.
Exactly. And not only that, but these kinds of questions (aside from
being just plain interesting to some people, like me) can stem from
perfectly reasonable, real-world situations. Perhaps you come across a
bug in your code and narrow it down to some weird C++ problem; you
construct a minimal example just as you are supposed to, and you come
here and ask about it without giving background context. That's
another good reason for posting those kinds of questions here. It's
*exactly* the kind of topic that this newsgroup exists for.
Feb 22 '08 #9
On 2008-02-22 17:12:35 -0500, Kira Yamato <ki*****@earthlink.netsaid:
On 2008-02-22 12:24:11 -0500, Johannes Bauer <df***********@gmx.desaid:
>Pete Becker schrieb:
>>A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.

Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the
answer, then just say so or better yet just be quiet.
If an apprentice carpenter asks whether he can use a hammer to drive in
a screw, he should be told "No." Speculating on whether it might or
might not work in some cases doesn't help him learn how to do his job.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 23 '08 #10
On Feb 22, 7:07 pm, Pete Becker <p...@versatilecoding.comwrote:
If an apprentice carpenter asks whether he can use a hammer to drive in
a screw, he should be told "No." Speculating on whether it might or
might not work in some cases doesn't help him learn how to do his job.
I completely agree. The carpenter should answer his question. The
friendly carpenter may even want to have a discussion about it. The
carpenter should *not* say "who cares?". And in any case, both
apprentice and carpenter would raise an eyebrow at and then disregard
the comment of a third guy who walked in the room out of nowhere and
said "why are you two talking about this?".

Unless you meant something else by your metaphor?
Feb 23 '08 #11
On 2008-02-22 19:07:12 -0500, Pete Becker <pe**@versatilecoding.comsaid:
On 2008-02-22 17:12:35 -0500, Kira Yamato <ki*****@earthlink.netsaid:
>On 2008-02-22 12:24:11 -0500, Johannes Bauer <df***********@gmx.desaid:
>>Pete Becker schrieb:

A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.

Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the
answer, then just say so or better yet just be quiet.

If an apprentice carpenter asks whether he can use a hammer to drive in
a screw, he should be told "No." Speculating on whether it might or
might not work in some cases doesn't help him learn how to do his job.
Are you kidding me? It is in the speculation of various scenarios that
we explore and learn the limits and strengths of our tools.

--

// kira

Feb 23 '08 #12
On Feb 22, 7:59 pm, Kira Yamato <kira...@earthlink.netwrote:
Are you kidding me? It is in the speculation of various scenarios that
we explore and learn the limits and strengths of our tools.
No, Pete is absolutely correct. There's no point in learning more
about your tools, or having interesting discussions about them. You
should just use them without question and get the job done without
thinking. Just don't hire "Versatile Coding" to do anything for you if
you need anything more than a typing grunt.
Feb 23 '08 #13
On Feb 22, 8:07 pm, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.comwrote:
No, Pete is absolutely correct. There's no point in learning more
about your tools, or having interesting discussions about them. You
should just use them without question and get the job done without
thinking. Just don't hire "Versatile Coding" to do anything for you if
you need anything more than a typing grunt.
Apologies, Pete. That was uncalled for -- I meant "Roundhouse
Consulting".
Feb 23 '08 #14
On 2008-02-22 19:13:39 -0500, "ja************@gmail.com"
<ja************@gmail.comsaid:
On Feb 22, 7:07 pm, Pete Becker <p...@versatilecoding.comwrote:
>If an apprentice carpenter asks whether he can use a hammer to drive in
a screw, he should be told "No." Speculating on whether it might or
might not work in some cases doesn't help him learn how to do his job.

I completely agree. The carpenter should answer his question. The
friendly carpenter may even want to have a discussion about it.
Interesting. You "completely agree" with something I clearly didn't say.
The
carpenter should *not* say "who cares?". And in any case, both
apprentice and carpenter would raise an eyebrow at and then disregard
the comment of a third guy who walked in the room out of nowhere and
said "why are you two talking about this?".

Unless you meant something else by your metaphor?
I meant just what I said. "No" is all that needs to be said, although
in a suitable setting it can be accompanied by laughter.

Unreadable code is unreadable code, regardless of whether its effect is
well defined.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 23 '08 #15
On 2008-02-22 19:59:31 -0500, Kira Yamato <ki*****@earthlink.netsaid:
On 2008-02-22 19:07:12 -0500, Pete Becker <pe**@versatilecoding.comsaid:
>On 2008-02-22 17:12:35 -0500, Kira Yamato <ki*****@earthlink.netsaid:
>>On 2008-02-22 12:24:11 -0500, Johannes Bauer <df***********@gmx.desaid:

Pete Becker schrieb:

A more important question, though, is "who cares?" Is it really
worhwhile spending time talking about the hypothetical meaning of an
expression that should never appear in real-world code? Even under
Java's rules, where the result is well defined, the code is abominable.

Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the
answer, then just say so or better yet just be quiet.

If an apprentice carpenter asks whether he can use a hammer to drive in
a screw, he should be told "No." Speculating on whether it might or
might not work in some cases doesn't help him learn how to do his job.

Are you kidding me? It is in the speculation of various scenarios that
we explore and learn the limits and strengths of our tools.
And what strengths and weaknesses do you expect to learn from exploring
the abomination that started this discussion?

The code is unreadable, regardless of whether its meaning is well
defined. It has no reason to exist in a production environment.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 23 '08 #16
On 2008-02-22 20:07:07 -0500, "ja************@gmail.com"
<ja************@gmail.comsaid:
On Feb 22, 7:59 pm, Kira Yamato <kira...@earthlink.netwrote:
>Are you kidding me? It is in the speculation of various scenarios that
we explore and learn the limits and strengths of our tools.

No, Pete is absolutely correct. There's no point in learning more
about your tools, or having interesting discussions about them. You
should just use them without question and get the job done without
thinking. Just don't hire "Versatile Coding" to do anything for you if
you need anything more than a typing grunt.
Sigh. You haven't even labeled this subthread "OT", despite making only
a personal attack.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 23 '08 #17
On 2008-02-22 20:09:11 -0500, "ja************@gmail.com"
<ja************@gmail.comsaid:
On Feb 22, 8:07 pm, "jason.cipri...@gmail.com"
<jason.cipri...@gmail.comwrote:
>No, Pete is absolutely correct. There's no point in learning more
about your tools, or having interesting discussions about them. You
should just use them without question and get the job done without
thinking. Just don't hire "Versatile Coding" to do anything for you if
you need anything more than a typing grunt.

Apologies, Pete. That was uncalled for -- I meant "Roundhouse
Consulting".
PLONK.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 23 '08 #18
On Feb 23, 8:24 am, Pete Becker <p...@versatilecoding.comwrote:
Sigh. You haven't even labeled this subthread "OT", despite making only
a personal attack.
I noticed; Google Groups removed the [OT]. A personal attack was
pretty much the only thing to say to the asinine comments you've been
making.
Feb 23 '08 #19
On Feb 23, 8:23 am, Pete Becker <p...@versatilecoding.comwrote:
And what strengths and weaknesses do you expect to learn from exploring
the abomination that started this discussion?
Pete, be honest -- what point are you arguing here? Somebody came to
comp.lang.c++ and asked a question about c++ that they were interested
in for their own curiosity. What, exactly, are you saying? That they
shouldn't have? That it was a stupid question? Great. Are you implying
that nobody should care about "silly" questions like that in C++, but
everybody *should* care that you think it's an irrelevant question? Is
that what is more important, letting everybody know that you think
those kinds of questions are stupid? Do you have a "point" that you
are trying to make beyond "I thought the poster's completely on topic
and honest question was dumb, and asking these kinds of questions
doesn't help me learn about my tools therefore it should help nobody
else?" Is there something that you want?
Feb 23 '08 #20
Kira Yamato schrieb:
>Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the answer,
then just say so or better yet just be quiet.
I know the anser - it comes up EVERY few days. It's a FAQ and people
should READ the FAQ before asking such pointless questions.

Regards,
Johannes

--
"PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
Rosenberg in dse <45**********************@newsspool3.arcor-online.net>
Feb 24 '08 #21
On 2008-02-24 09:29:52 -0800, Johannes Bauer <df***********@gmx.desaid:
Kira Yamato schrieb:
>>Exactly, I fully second that. I do not understand at all why this exact
question comes up in this group (and in comp.lang.c, too, BTW) every few
days. Kind of annoying. You should think people have more important
problems.

It's called knowing your tools well. If you just don't know the answer,
then just say so or better yet just be quiet.

I know the anser - it comes up EVERY few days. It's a FAQ and people
should READ the FAQ before asking such pointless questions.
No, it's more than that. You can learn to use your tools with things
like the canonical i=i++. The code in question here is far more
complex, with far too many issues. Studying it won't teach anything
except frustration.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Feb 25 '08 #22
ja************@gmail.com schrieb:
B.S.
B.S. is what YOU wrote. Your forging of quotes impressively demonstates
your lack of ability to respond adequately to posts.

That's pretty pathetic. You're pretty pathetic.

Johannes

--
"PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
Rosenberg in dse <45**********************@newsspool3.arcor-online.net>
Feb 27 '08 #23

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.