Simplest way to for loop
-
Sorry about my language, about shifting data in structs I was referring to auto optimization of data type sequences in structs.
To position bools in same row , ints same etc not bit shift.
So code is readable with long struct containing dif types and less size for machine to avoid cache misses.@Q139 It would be bad if compiler reordered your struct elements. Code that relies on the addresses of these members to be in certain order relative to each other or to the beginning of the struct or stuff like
offsetof
would easily break. Also it would not help readability while debugging for example - if you put a bool at the top of your struct it's gonna sit at the memory address of your instance, If compiler moved it somewhere how would you know? Serialization could also be an issue. No, it's better to leave the order of members to the programmer and make it clear how members are laid out. -
The other day I learned that gcc will convert a tail call optimized recursive routine into a while loop and thus no limit to recursion iterations (there are probably caveats to this, but it won't likely cause an SO). That is when I realized I should not spend my time on second guessing the compiler unless I am presented with a reason. Optimizing for the sake of optimizing is wasted effort. Find bottlenecks first. They are probably not where you think they are.