|Personally, I think the "+ 0" part is to convert the return value from sizeof() which is size_t to int.|
Good idea, but the type of sizeof(e) + 0
is smaller than int
. See [expr.arith.conv] for the actual rules:
Therefore I consider this an unlikely explanation, not least because it would be surprising if it did occur; why should the type of __crt_countof(my_array)
change signedness between platforms, inviting undefined behavior?
|The [Stack Overflow] answer they accepted|
First, declarations are not expressions or type names, so any attempt to sizeof(declaration)
, such as
doesn't compile. So it seems unlikely that *__countof_helper(_Array)
could be interpreted as a declaration, even if we ignore that it is never a declaration according to standard C++.
Second, if sizeof(*__countof_helper(_Array))
is itself a function declaration, than there's no return type, the name of the function is sizeof
, and/or somehow *__countof_helper(_Array)
is a type name.
I believe the most vexing parse idea can be discounted.
|It's MS and Windows. Whatever the original reason(s) for doing it, it is now established as The Way To Do Things.|
The only other options I can recall are that it could interact with an external tool or maybe has something to do with an edge case thanks to some language extension.
Or, it could be a typo. :-)