These do the same thing (as far as i know) but which one is more correct ?
Are there any pros and cons, etc ?
Are there any differences at all that is noteworthy ?
---------------------------------------------------------------------------------------------------
From: stdlib.h
extern "C++" { template <typename _CountofType, size_t _SizeOfArray> char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; #define _countof(_Array) (sizeof(*__countof_helper(_Array)) + 0) }
Question: Why "+ 0" ? To prevent compiler bug ?
---------------------------------------------------------------------------------------------------
From: WinNT.h (Microsoft SDK)
extern "C++" // templates cannot be declared to have 'C' linkage template <typename T, size_t N> char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N]; #define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
This is the same as the one above but without the strange "+ 0".
---------------------------------------------------------------------------------------------------
From: WSPiApi.h (Microsoft SDK)
template <typename __CountofType, size_t _N> char (&__wspiapi_countof_helper(__CountofType (&_Array)[_N]))[_N]; #define _WSPIAPI_COUNTOF(_Array) sizeof(__wspiapi_countof_helper(_Array))
---------------------------------------------------------------------------------------------------
So the main question would be: pointer vs reference, pros and cons anyone know ?