Guarded COUNTOF macro. Thanks to Graham Bull for the suggestion

reviewable/pr7/r1
Jeffrey Walton 2015-07-05 17:53:42 -04:00
parent aa8bb8c5cd
commit 8386b3f139
1 changed files with 7 additions and 5 deletions

8
misc.h
View File

@ -72,11 +72,13 @@ struct CompileAssert
// ************** counting elements in an array *************** // ************** counting elements in an array ***************
// VS2005 added _countof macro, fails on pointers // VS2005 added _countof macro, fails on pointers
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #ifndef COUNTOF
# if defined(_MSC_VER) && (_MSC_VER >= 1400)
# define COUNTOF(x) _countof(x) # define COUNTOF(x) _countof(x)
#else # else
# define COUNTOF(x) (sizeof(x)/sizeof(x[0])) # define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
#endif # endif
#endif // COUNTOF
// ************** misc classes *************** // ************** misc classes ***************