Code: Select all
Option(OnChange f) ... idx(f ? counter++ : 0)
Moderator: Ras
Code: Select all
Option(OnChange f) ... idx(f ? counter++ : 0)
Don't forget to changemcostalba wrote:This won't work (I have tried), but I won't tell you whysyzygy wrote: You could use a static counter that you increase in the Option() constructor and that you use instead of Options.size().
Code: Select all
if (it->second.idx == idx)
Code: Select all
if (it->second.idx == 2 * idx)
It is not only this, it is not enough. And of course we are not running for a code obfuscation eventsyzygy wrote:Don't forget to changemcostalba wrote:This won't work (I have tried), but I won't tell you whysyzygy wrote: You could use a static counter that you increase in the Option() constructor and that you use instead of Options.size().intoCode: Select all
if (it->second.idx == idx)
Code: Select all
if (it->second.idx == 2 * idx)
The operator<< approach is short and cute, but maybe too cutemcostalba wrote:Ok I have pushed a patch that removes the trickery from options initializations:
https://github.com/mcostalba/Stockfish/ ... f6649328a5
I failed to stick to this quiz rules because I used another operator '<<' instead of the required '+'.
But at least now solution seems correct.
Thanks also to Rein for his suggestion: I didn't realized such solution was also possible. Nice, although perhaps a bit complex.
Code: Select all
o["bla"] << Option(val1) << Option(val2);
Rein Halbersma wrote:The operator<< approach is short and cute, but maybe too cutemcostalba wrote:Ok I have pushed a patch that removes the trickery from options initializations:
https://github.com/mcostalba/Stockfish/ ... f6649328a5
I failed to stick to this quiz rules because I used another operator '<<' instead of the required '+'.
But at least now solution seems correct.
Thanks also to Rein for his suggestion: I didn't realized such solution was also possible. Nice, although perhaps a bit complex.First, it's a bit intrusive to store ordering info in the Option class itself rather than in its map-like container (the Standard Library always uses non-intrusive containers). Second (minor nitpick), you have to be careful never to write something like
Code: Select all
o["bla"] << Option(val1) << Option(val2);
I understand all of that. My point is, if you take a C source, stick your finger in it at point A and say "here is a sequence point in the program" it MIGHT not really be there. That entire block of code might not "be there" in fact. I guess we could call this the "undefined behavior of sequence points" since they are not guaranteed to exist on a 1-to-1 correspondence between what runs and what is in the source.wgarvin wrote:Sequence points are an abstract thing that exists in the original source program. The compiled program needs to behave "as if" any side effects from before a sequence point, occur before any side effects from after that sequence point. Of course the compiler can mix the instructions together for optimization purposes, as long as the partial ordering of side effects dictated by the sequence points is properly enforced (in single-threaded code, etc. etc.)bob wrote:No argument with one exception. After the inlining stage of the compiler is done, some of the procedure calls are now missing. The compiler sees the inlined code for the actual compilation step, and it is no longer aware of a procedure call, nor of that specific sequence point. Certainly the inlined code will have its own set of sequence points. My comment was simply that the "sequence points" you see MIGHT not exist at all, in reality. Saying "there is a sequence point right here" can, therefore, be a bit inaccurate. In fact, in some cases, a procedure might be removed completely AND not inlined either, if it is found to be useless code. Hence my comment. Nothing more, nothing less.mar wrote:I think the point is that the compiler can do whatever optimizations it likes an long as the optimized program behaves exactly the same as if it was synchronized at sequence points.
If a compiler performs inlining and then during subsequent optimizations, fails to preserve the semantics of the sequence points that originally existed in the source code, then that compiler is broken.
In the C source it is really there. The compiler does not rewrite the C source when you are not looking. Write the source, save it, go to sleep, load it in your editor, still there, unchanged.bob wrote:I understand all of that. My point is, if you take a C source, stick your finger in it at point A and say "here is a sequence point in the program" it MIGHT not really be there.wgarvin wrote:Sequence points are an abstract thing that exists in the original source program. The compiled program needs to behave "as if" any side effects from before a sequence point, occur before any side effects from after that sequence point. Of course the compiler can mix the instructions together for optimization purposes, as long as the partial ordering of side effects dictated by the sequence points is properly enforced (in single-threaded code, etc. etc.)bob wrote:No argument with one exception. After the inlining stage of the compiler is done, some of the procedure calls are now missing. The compiler sees the inlined code for the actual compilation step, and it is no longer aware of a procedure call, nor of that specific sequence point. Certainly the inlined code will have its own set of sequence points. My comment was simply that the "sequence points" you see MIGHT not exist at all, in reality. Saying "there is a sequence point right here" can, therefore, be a bit inaccurate. In fact, in some cases, a procedure might be removed completely AND not inlined either, if it is found to be useless code. Hence my comment. Nothing more, nothing less.mar wrote:I think the point is that the compiler can do whatever optimizations it likes an long as the optimized program behaves exactly the same as if it was synchronized at sequence points.
If a compiler performs inlining and then during subsequent optimizations, fails to preserve the semantics of the sequence points that originally existed in the source code, then that compiler is broken.
Impossible if the compiler implements the C standard correctly.syzygy wrote:Both receiving I/O and reading system_time involve side effects. A compiler is not allowed to reorder side effects across sequence points. There are sequence points between "blocked wait for message" and the evaluation of "message == go" and between the evaluation of "message == go" and "inital_time = system_time()".
So scenario 1 is impossible.