Re: (i++ * i++)
thp_at_cs.ucr.edu
Date: 04/16/04
- Next message: Jerry Coffin: "Re: Hash table in C++? STL?"
- Previous message: CBFalconer: "Re: const structure & member pointers"
- Maybe in reply to: thp_at_cs.ucr.edu: "Re: (i++ * i++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 16 Apr 2004 04:49:29 +0000 (UTC)
Nils Petter Vaskinn <no@spam.for.me.invalid> wrote:
: On Wed, 24 Mar 2004 15:04:32 +0000, Christopher Benson-Manica wrote:
:
:> Thomas Matthews <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> spoke thus:
[...]
:>
:> It seems that you're responding to OP's broken code. Either that or
:> you saw an i++ in Nils' code where where there in fact was none.
:> Either that or you believe the expression i may result in an increment
:> operation ;)
:
: Either that or he meant that since the intent of the OP's code isn't
: obvious my solution won't nessessarily match it. But my example can be
: trivially modified to account for any conceivable intent of the original
: code:
:
: // if the intent was 5*6 leaving i as 7
: int i = 5;
: std::cout << (i * i++) << std::endl;
: i++;
Sorry, "i*i++" begets undefined behavior, the former value of the
modified object is used for purposes other than to determine the new
value of that object. (I don't like it either!)
: ...
:
: // if the intent was 5*6 leaving i as 6
: int i = 5;
: std::cout << (i * i++) << std::endl;
Still undefined behavior.
: ...
:
: // if the intent was 5*5 leaving i as 6
: int i = 5;
: std::cout << (i * ++i) << std::endl;
Still undefined behavior.
: ...
: // if the intent was undefined behaviour
: int *i;
: std::cout << *i << std::endl;
Right, because i is uninitialized.
C89 6.3 and its vestiges in C99 and C++ are unfortunate design flaw in
C/C++. A significant fraction of the practicing C/C++ programmers are
unaware of this loophole for optimizers and/or don't understand it.
Someday that lack of awareness will hurt someone.
Tom Payne
- Next message: Jerry Coffin: "Re: Hash table in C++? STL?"
- Previous message: CBFalconer: "Re: const structure & member pointers"
- Maybe in reply to: thp_at_cs.ucr.edu: "Re: (i++ * i++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|