flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > In f(g(x),h(y)), which should i do first - g or h? |
Author |
|
Furs 13 Aug 2017, 16:51
C/C++ does not guarantee the order of evaluation of function parameters. It seems weird, but not even C++17 fixed it completely. This is why I stress to people that they should not rely on something "just because it works" since the compiler is allowed to do it in any order. This is actually a big source of problems for variadic templates and their parameter pack expansions within a function...
The reason for this is due to optimizations. If the compiler is able to reorder the function calls in parameter evaluation so that the code is better, it has the opportunity to do it. If the language didn't allow it, the compiler would have no such freedom. If you want a specific order, use something like: Code: int F(int x, int y) { int _g = g(x); return f(_g, h(y)); } |
|||
13 Aug 2017, 16:51 |
|
revolution 14 Aug 2017, 04:50
I think this belongs in the HLL section so I moved it.
|
|||
14 Aug 2017, 04:50 |
|
revolution 14 Aug 2017, 19:35
The more I learn about C the more I realise it has many subtle and devastating traps for the unwary programmer. You can't just write the code, you have to write the code and then examine and maintain it for the next infinity years to make sure that the latest update to the compiler doesn't break it.
|
|||
14 Aug 2017, 19:35 |
|
DimonSoft 14 Aug 2017, 20:09
revolution wrote: The more I learn about C the more I realise it has many subtle and devastating traps for the unwary programmer. You can't just write the code, you have to write the code and then examine and maintain it for the next infinity years to make sure that the latest update to the compiler doesn't break it. Well, in fact most cases of undefined behaviour are actually things that are strange for a HLL, like relying on NULL-pointer dereferencing, overflowed values, etc. So, if you avoid such stuff and a few special cases, you’re almost safe. This fact doesn’t render C/C++ being good languages though. |
|||
14 Aug 2017, 20:09 |
|
revolution 14 Aug 2017, 20:20
Why does C even have undefined behaviour? Should it not refuse to compile because of bad or contradictory input?
|
|||
14 Aug 2017, 20:20 |
|
Furs 14 Aug 2017, 21:31
revolution wrote: Why does C even have undefined behaviour? Should it not refuse to compile because of bad or contradictory input? This may sound ideal, but in fact royally pisses me (and a lot of people) off. You can't even use reinterpret_cast or unions with type-punning (or an equivalent C-style cast; basically, you can't read the bytes of a memory as a type other than the original type, period). That would be so fucking useful for some abstract functions. GCC used to allow it as a special extension, but now it fails to compile "because the language says so" (not because of technical limitations), which pisses me off. I hope a special place in hell is reserved for the pathetic piece of shit who even cheered for this "feature". I can understand a WARNING for undefined behavior (that can be suppressed) but flat-out ERRORING out because of a retarded incompetent moron who thinks "his way is the only way to code"? It's not often I wish bad on people but in this case, you know who you are (yea I know even his name but won't say it here for... reasons; he's of course part of the shitty C++ committee) Anyway, undefined behavior exists because every platform is different. C/C++ try to be portable, but won't (shouldn't) disallow you from using platform-specific quirks if you want to do it. |
|||
14 Aug 2017, 21:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.