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.

43 lines
1.5 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: countof.h
  7. *
  8. * Contents:
  9. *
  10. * History: 12-May-98 JeffRo Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef __COUNTOF_H__
  14. #define __COUNTOF_H__
  15. #pragma once
  16. /*-------------------------------------------------------------------*/
  17. /* Define a safe function that will return the count of elements */
  18. /* in an array. It is safe because it won't compile if the argument */
  19. /* is not an array, whereas the classic macro to do this: */
  20. /* */
  21. /* #define countof(a) (sizeof(a) / sizeof(a[0])) */
  22. /* */
  23. /* will compile if given a pointer, but will almost certainly not */
  24. /* give the expected result. */
  25. /* */
  26. /* Unfortunately, the compiler won't compile this yet. */
  27. /*-------------------------------------------------------------------*/
  28. #if _MSC_VER > 1400
  29. #error See if the compiler can handle the countof<T> template now.
  30. #endif
  31. #ifdef COMPILER_WONT_COMPILE_THIS
  32. template <typename T, size_t N>
  33. inline size_t countof(T (&a)[N])
  34. { return N; }
  35. #else
  36. #define countof(x) (sizeof(x) / sizeof((x)[0]))
  37. #endif
  38. #endif // __COUNTOF_H__