Re:Generate raw WAV output by hooking malloc and read
by thegeomaster on Tuesday July 29, 2014 @02:37AM
(#8100977)
I don't get it, isn't sizeof(data) always the same, and usually either 4 or 8?
[ Parent
| on HN ]
Re:Generate raw WAV output by hooking malloc and read
by fredophile on Tuesday July 29, 2014 @10:48AM
(#8102473)
It's always the same for your compiler. Using sizeof improves the portability of the code. Because sizeof is calculated at compile time it doesn't make the code any less efficient.
We often think about pointers as being 4 bytes but that isn't necessarily the case. How would a 32 bit pointer map to the addressable memory of 64 bit hardware?
Re:Generate raw WAV output by hooking malloc and read
by reubenmorais on Tuesday July 29, 2014 @03:55PM
(#8104588)
I think his point is more about clamping the value than about using sizeof. It indicates the author expected that value to vary, but it doesn't.
Re:Generate raw WAV output by hooking malloc and read
by fredophile on Tuesday July 29, 2014 @08:11PM
(#8105722)
Depending on your application I can see where you might still want to clamp the result. However, I think you're right in this case since the clamped range doesn't make much sense here.
Re:Generate raw WAV output by hooking malloc and read
by taejo on Tuesday July 29, 2014 @03:31AM
(#8101089)
Since sizeof is a compile-time construct, it's always always the same (in C; in C++ there are templates to consider)
Re:Generate raw WAV output by hooking malloc and read
by nitrogen on Tuesday July 29, 2014 @10:34AM
(#8102414)
I haven't read the code, but it looks like this is a bug, or at least superfluous