LWN.net Logo

Not Again

Not Again

Posted Apr 17, 2012 22:42 UTC (Tue) by tjc (subscriber, #137)
In reply to: Not Again by juliank
Parent article: PHP: a fractal of bad design (fuzzy notepad)

That's a feature -- it gives the compiler more opportunities for optimization. If you're going to write tricky code in C, it's important to understand sequence points.


(Log in to post comments)

Not Again

Posted Apr 18, 2012 1:10 UTC (Wed) by jzbiciak (✭ supporter ✭, #5246) [Link]

It does, but it's so easy to forget some of these rules that it can lead to subtle, mind boggling errors -- errors that may not show up until you change compilers or compile flags, and may never evoke a warning from the compiler. The P_Rand() - P_Rand() example I gave elsewhere is a prime example, and I don't think anyone would have called John Carmack (or whoever wrote that idiom at id) an amateur.

So, while it's all well and good to say "Write tricky C only if you understand sequence points," there are plenty of non-tricky sequences that are nonetheless ill defined and subject to implementation defined or undefined behavior.

Throw in modern hardware and multithreading, and it's.... exciting. Sequence points only barely help you there. The Linux "memory barriers" document is an informative read.

Not Again

Posted Apr 19, 2012 22:12 UTC (Thu) by BenHutchings (subscriber, #37955) [Link]

The most important things to understand about sequence points being that they are not points and do not generally define a sequence. :-)

Not Again

Posted Apr 21, 2012 15:50 UTC (Sat) by tjc (subscriber, #137) [Link]

What would you call them then?

Not Again

Posted Apr 21, 2012 16:23 UTC (Sat) by BenHutchings (subscriber, #37955) [Link]

I would refer to a partial ordering of operations. Anyway, this was fixed in the latest standard (though unfortunately multithreading and atomic operations make this a lot more complex).

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds