4 ms·
void* read( int fd, void * data, size_t count) { ... gen_square_wave( 44100 , CLAMP(count, 20, 20000 ), CLAMP( sizeof(data), 100 , 1700), 0.7 );
by thegeomaster 12y ago
void* read( int fd, void * data, size_t count)
{
...
gen_square_wave( 44100 , CLAMP(count, 20, 20000 ), CLAMP( sizeof(data), 100 , 1700), 0.7 );
I don't get it, isn't sizeof(data) always the same, and usually either 4 or 8?
- taejo 12y agoSince sizeof is a compile-time construct, it's always always the same (in C; in C++ there are templates to consider)
- nitrogen 12y agoI haven't read the code, but it looks like this is a bug, or at least superfluous
- bitwize 12y agoYeah, the result of the sizeof operator always compiles to a constant. It may vary from system to system and compiler to compiler, but it's written into the executable as a constant.
- fredophile 12y agoIt'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?
- reubenmorais 12y agoI 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.
- fredophile 12y agoDepending 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.