Skip to main content

Timeline for Readability a=b=c or a=c; b=c;?

Current License: CC BY-SA 2.5

9 events
when toggle format what by license comment
Feb 2, 2014 at 19:51 comment added Ben Voigt @Mr.Smith: That is an interesting (and correct) observation, but c is not a property so it doesn't apply here.
Feb 2, 2014 at 19:50 comment added Mr. Smith strictly speaking, a=b=c=d; in C# is not the same as writing c=d;b=c;a=b;; this is apparent when c is a property (its get won't be invoked with a=b=c=d; but it will with c=d;b=c;a=b).
Mar 21, 2011 at 14:33 comment added Ben Voigt @Martin: POD-ness has not much to do with it. A type can be POD and still have a user-defined operator=. Anyway, if the operator= is user-defined and not inline, the compiler can't reorder, but in the common case reordering is possible.
Mar 21, 2011 at 6:59 comment added Loki Astari @Ben Voigt : With the assumption that the variables are POD. If not then the compiler can re-order the assignments. So unless you want to have different style one for POD and another for class types you leave yourself open to the confusion of the syntax.
Mar 21, 2011 at 4:56 comment added Ben Voigt @Martin: Again, unless some of the variables are volatile, the compile can reorder the assignments. So which order is really "equivalent" is more a matter of pedanticism than anything.
Mar 21, 2011 at 4:11 comment added Loki Astari The fact that you have to point out that the assignment order is not obvious, should be a recommendation not to use it.
Mar 21, 2011 at 2:37 comment added Ben Voigt @Paulo: Good point. I'm specifically listing the behavior of C++, but I thought the other languages retain compatibility in this area. You're right that b=c vs b=0 only matters if some of the variables are volatile, the main point I was making was that c gets assigned before a, although again that should make a difference except for volatile, since the compiler can do reordering of writes to normal variables.
Mar 21, 2011 at 2:24 comment added Paŭlo Ebermann If you do such assertions on a multiple-language question, please specify for which language they are valid. I think in Java it would be c = 0; b = 0; a = 0; instead. (The differences would only be observable if using volatile variables, though.)
Mar 21, 2011 at 2:14 history answered Ben Voigt CC BY-SA 2.5