3 ms·
Really appreciate everyone's replies! A related question about my example: what if I want to assign the pointer dereference to `tmp` to improve readability (rat
by pjungwir 12y ago
Really appreciate everyone's replies! A related question about my example: what if I want to assign the pointer dereference to `tmp` to improve readability (rather than avoid multiple traversals). Is there any reason not to use a tmp variable (presumably with a better name)?
- sjolsen 12y ago>what if I want to assign the pointer dereference to `tmp` to improve readability I personally find code like that harder to follow. The first version is clearer than the second (and you forgot to take the address of foo->bar->baz[i]).
- pjungwir 12y ago> and you forgot to take the address of foo->bar->baz[i] Ha, I was afraid of that. :-) Still re-learning when I need that with arrays and when not.
- haberman 12y ago> Is there any reason not to use a tmp variable (presumably with a better name)? Nope -- shouldn't hurt at all. It's interesting to me that LuaJIT recommends not using temp variables like this because they can hurt optimization for LuaJIT. That's obviously very different than C in almost every way, I just mention it because it was so surprising to me that there is a situation (in any optimized language) where a temp variable could hurt optimization.
- exDM69 12y agoNo, it doesn't hurt to have an extra local variable if you have compiler optimization enabled. If it would be a global or member of struct/class, that's a different deal. It's useful to add some variables to be inspected in the debugger.