diff options
author | Elliott Hughes <enh@google.com> | 2011-04-15 18:00:11 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-04-15 18:00:11 -0700 |
commit | 027ff8072c5387a7a1736dbffe2808c84222939a (patch) | |
tree | aa5a6cab37087158d0a142de49d67994821429f2 | |
parent | 2f82af198bf9e856115d1a809556e9df46bd9bab (diff) | |
download | libnativehelper-027ff8072c5387a7a1736dbffe2808c84222939a.tar.gz |
In C++, we can offer a better NELEM.
Change-Id: Iaedc727becb4af1c779299d4da7c91bd522fe9cc
-rw-r--r-- | include/nativehelper/JNIHelp.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h index 1b5ff0c..c3e0320 100644 --- a/include/nativehelper/JNIHelp.h +++ b/include/nativehelper/JNIHelp.h @@ -27,10 +27,23 @@ #include "utils/Log.h" #include <unistd.h> +#ifdef __cplusplus + +// Type-safe implementation from Google's "base/macros.h". +#ifndef NELEM +template <typename T, size_t N> char (&JniArraySizeHelper(T (&array)[N]))[N]; +#define NELEM(array) (sizeof(JniArraySizeHelper(array))) +#endif + +#else + +// Backwards-compatible C cruft. #ifndef NELEM # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) #endif +#endif + #ifdef __cplusplus extern "C" { #endif |