java - Defined argument evaluation order leads to sub-optimal code? -


It is a known fact that argument evaluation commands are not defined in C and C ++: for example: foo (A (), b ()) In the above call it depends on the implementation of the compiler to decide which evaluation evaluates and so on which further executes. Recently one of my friends asked why the order of unspecified evaluation in C or C ++ is when I googled it, I found out that an evaluation order will lead to sub optimal code generation. But how is it? Why would a defined order of evaluation of logic take the sub-optimal code? And when I referenced Java's argument evaluation order. I got the following in the device.

15.7.4. Evaluation of logic lists from left-to-right

In a method or constructor invocation or class instance expression expression, argument expression can be different in coma, separated from commas. Each argument expression is being fully evaluated from any part of any logic expression before its right. If a logic expression is evaluated suddenly, then any part of any logic expression on its right is not evaluated?

Due to this case, the logic evaluation order defined in Java is, but saying that C or C ++ compilers provide sub-optimal code if such behavior is specified Looks a bit weird Can you put some light on this?

It is partially historical: for example, with some registers, on a processor, a traditional ( And simple) optimization techniques, evaluation of sub-expansions, which are the first most registers required. If a subexpression requires 5 registers, and the other 4, for example, anyone who requires 4 for it, can save the result of anyone requiring 5 in the register.

This is probably less relevant to the idea. If there is no side effects of an expression, the compiler (even in Java) can be reordered, or does not alter the behavioral behavior of the redirectioning program. Modern compilers are capable of determining better than compilers 20 or more years ago (when the C ++ rule was made). And possibly, when they are not able to determine it, then you are making enough in every expression that there is no difference in additional slot memory.

At least, this is my inner feeling that I have been told by at least one person who actually works on the adapter that will make a significant difference, so I will not say that I I'm sure about

EDIT:

Just to add some comments in relation to the Java model, when Java was designed, it was created as an interpreted language. Extreme performance was not an issue; The goal was extreme security, and fertility capacity. In this way, it specifies many things very accurately, so that any program compiled can be treated without taking into account the platform. There should be no undefined behavior, no implementation is defined behavior, and there is no unspecified behavior, despite the cost (but with the assumption that it can be done at a fair price on most widely machines) C (and indirect) An early design goal of C ++ was that the cost of unnecessary extra runtime should be minimal, stability between platforms was a goal Only (because at the time, there is considerable variation in general platforms), and security, while a concern was not initial, although the behavior has developed some, yet one goal can be supported, efficiently, out of any machine that is out there May exist. Without the need of the latest, most complicated compiler techniques and naturally leads different solutions towards various solutions.


Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -