![]() ![]() That kind of code must be strongly avoided. On another compiler/architecture the output result may be different. That means the behaviour of your code could be anything. It's very important to consider that your code produces an undefined behaviour. Your "a b" input will execute the case 2 != 0 returning "one". That why you probably obtain your unexpected result. In other words, the code will be optimised as: if (i != 0) In the other case ( i = 0) the function body will continue. The f function will be decomposed in the following: f(int): # rax, Īs you can see, the conditional branch is the instruction je. Here you can see an online disassemble (with clang 4.0.1). The variables from which the conditional jump depends are stored in the registers. ![]() If those would be missing then the CPU would not be Turing-complete. However I think I can still provide an answer to your question. For example the processors in Intel's x86 family support the instructions jnz (jump if not zero), jne (jump not equal), and so on. How could I disable this optim, to really see the crashes due to bad code, instead of having them shadowed ? $ clang -versionĬlang version 4.0.1 (tags/RELEASE_401/final)Ĭompilers optimisations are strongly architecture-version dependent. What kind of optimizations could just assume i want the last if() to be a "default case" ? Now, compiling with optimizations: $ clang++. 20447 illegal hardware instruction (core dumped). return_optims_ifs.cpp:10:1: warning: control may reach end of non-void function Std::cout << "Passed " << f(argc - 1) << " arguments." << std::endl Ĭompiling without optimizations: $ clang++. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |