AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
macros.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 
4 #ifndef INCLUDED_SAL_MACROS_H
5 #define INCLUDED_SAL_MACROS_H
6 
7 #include <stddef.h>
8 
9 #ifndef SAL_N_ELEMENTS
10 # if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
11  /*
12  * Magic template to calculate at compile time the number of elements
13  * in an array. Enforcing that the argument must be an array and not
14  * a pointer, e.g.
15  * char *pFoo="foo";
16  * SAL_N_ELEMENTS(pFoo);
17  * fails while
18  * SAL_N_ELEMENTS("foo");
19  * or
20  * char aFoo[]="foo";
21  * SAL_N_ELEMENTS(aFoo);
22  * pass
23  *
24  * Unfortunately if arr is an array of an anonymous class then we need
25  * C++0x, i.e. see
26  * http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#757
27  */
28  template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S];
29 # define SAL_N_ELEMENTS(arr) (sizeof(sal_n_array_size(arr)))
30 # else
31 # define SAL_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
32 # endif
33 #endif
34 
35 #ifndef SAL_STRINGIFY
36 # define SAL_STRINGIFY_ARG(x) #x
37 # define SAL_STRINGIFY(x) SAL_STRINGIFY_ARG(x)
38 #endif
39 
40 #endif
41 
42 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */