[PATCH 1/2] utils: Define ARRAY_SIZE() if not yet defined

Thomas Haller thaller at redhat.com
Wed Aug 27 04:48:44 PDT 2014


On Wed, 2014-08-27 at 12:26 +0200, Thomas Graf wrote:
> Allows using ARRAY_SIZE() in src examples
> 
> Signed-off-by: Thomas Graf <tgraf at suug.ch>
> ---
>  include/netlink-private/netlink.h | 2 --
>  include/netlink/utils.h           | 4 ++++
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
> index 39f4dff..dcc3ad2 100644
> --- a/include/netlink-private/netlink.h
> +++ b/include/netlink-private/netlink.h
> @@ -144,8 +144,6 @@ static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
>  	return ret;
>  }
>  
> -#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
> -
>  /* This is also defined in stddef.h */
>  #ifndef offsetof
>  #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
> diff --git a/include/netlink/utils.h b/include/netlink/utils.h
> index 6b4b787..9c64eba 100644
> --- a/include/netlink/utils.h
> +++ b/include/netlink/utils.h
> @@ -118,6 +118,10 @@ enum {
>  };
>  int nl_has_capability (int capability);
>  
> +#ifndef ARRAY_SIZE
> +#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
> +#endif

isn't it problematic to define ARRAY_SIZE in our public headers?

I feel we should not define anything without our nl specific prefixes.


maybe we can add another project-internal (private) header, that can be
used by ./src/ too?


Thomas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20140827/1a3266a1/attachment.sig>


More information about the libnl mailing list