3 ms·
sizeof does not perform evaluation of its argument in the traditional sense, so this is not an issue here.
by saagarjha 7y ago
sizeof does not perform evaluation of its argument in the traditional sense, so this is not an issue here.
- Stratoscope 7y agoAh yes, thanks for the reminder. This is also the reason why COUNTOF is valid for a zero-length array. Even though array[0] is non-existent in this case, it's fine to pass it to sizeof to get the size of an array element as if there were one. After all, a pointer can point one element past the end of an array.
- saagarjha 7y ago> After all, a pointer can point one element past the end of an array. Hmm, I wouldn’t put it that way, since sizeof(array[1]) would work just as well. I like to think of sizeof running the type checker on the expression provided and then looking up the size of the type of the expression: this makes it clear that the thing inside can be completely bogus as long as it is syntactically correct.
- Stratoscope 7y agoThat is a much better way to look at it, thanks!