Suppose I have a statement like :
I'm not getting any trouble with it, butCode:a.send_buffer.front().p.get_main_data();
Is is better to put parentheses ?
or is it sufficiently defined that the order should be followed ?
This is a discussion on Must the order of execution(in this case) be left to right? within the C++ Programming forums, part of the General Programming Boards category; Suppose I have a statement like : Code: a.send_buffer.front().p.get_main_data(); I'm not getting any trouble with it, but Is is better ...
Suppose I have a statement like :
I'm not getting any trouble with it, butCode:a.send_buffer.front().p.get_main_data();
Is is better to put parentheses ?
or is it sufficiently defined that the order should be followed ?
Manasij Mukherjee | gcc-4.8.0 @Arch Linux
Slow and Steady wins the race... if and only if :
1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !
I do not think that there is any other way to evaluate the expression.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Why not?
If a similar expression contains ->* or .* or similar operators related to pointers, couldn't a function encountered later in the expression return a pointer to a member of an object encountered earlier ? I think I have seen examples like that in the Qt Documentations .
Manasij Mukherjee | gcc-4.8.0 @Arch Linux
Slow and Steady wins the race... if and only if :
1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !
Once a function's arguments have been evaluated, a sequence point is introduced.Originally Posted by manasij7479
Another related way to look at it: consider that we could write x.y() as y(x), if we pretend that the object on which the member function operates was passed (by reference) as the first argument to the function. This way, we could re-write a.send_buffer.front().p.get_main_data() as get_main_data(front(a.send_buffer).p). Clearly, in this form, adding parentheses isn't going to help.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Operators in C and C++ - Wikipedia, the free encyclopedia
Dot has the same precedence as () (read: the only other operator in the example) so the expression is evaluated from left to right. That's what associativity is.
Originally Posted by phantomotap