Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.2 KiB

  1. ////
  2. // Macro for dimension of static arrays.
  3. #if !defined(FUSION_INC_NUMBEROF_H_INCLUDED_)
  4. #define FUSION_INC_NUMBEROF_H_INCLUDED_
  5. #pragma once
  6. #if defined(NUMBER_OF)
  7. #undef NUMBER_OF
  8. #endif
  9. #if FUSION_USE_CHECKED_NUMBER_OF
  10. //
  11. // Note!
  12. //
  13. // Use of this "checked" number of macro causes CRT initializers to have to run
  14. // for static/constant arrays.
  15. //
  16. // We cannot enable this for fusion right now, but turning it on and running at
  17. // least will lead to the compiler errors
  18. //
  19. // Static arrays will match this signature.
  20. template< typename T
  21. >
  22. inline
  23. SIZE_T
  24. NUMBER_OF_validate
  25. ( void const *
  26. , T
  27. )
  28. throw()
  29. {
  30. return (0);
  31. }
  32. // Other things (e.g. pointers) will match this signature.
  33. template< typename T
  34. >
  35. inline
  36. void
  37. NUMBER_OF_validate
  38. ( T * const
  39. , T * const *
  40. )
  41. throw()
  42. {
  43. }
  44. // Use the size of the validation function's return type to create an
  45. // error when this macro is misused.
  46. #define NUMBER_OF(array) \
  47. (sizeof(NUMBER_OF_validate((array), &(array))), \
  48. (sizeof((array)) / sizeof((array)[0])))
  49. #else
  50. #define NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
  51. #endif // FUSION_USE_CHECKED_NUMBER_OF
  52. #endif // !defined(FUSION_INC_NUMBEROF_H_INCLUDED_)