From c3ead528287db5ae779fc7ca00f935516d685c2a Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 26 Oct 2016 17:03:49 +0200 Subject: [PATCH] MdePkg/Include/Base.h: introduce the ARRAY_SIZE() function-like macro Several modules use ARRAY_SIZE() already; centralize the definition. (The module-specific macro definitions are guarded by #ifndef directives at this point.) Cc: Ard Biesheuvel Cc: Cecil Sheng Cc: Chao Zhang Cc: Dandan Bi Cc: Daryl McDaniel Cc: David Wei Cc: Eric Dong Cc: Feng Tian Cc: Gary Lin Cc: Jaben Carsey Cc: Jeff Fan Cc: Jiaxin Wu Cc: Jordan Justen Cc: Liming Gao Cc: Michael D Kinney Cc: Ruiyu Ni Cc: Siyuan Fu Cc: Star Zeng Cc: Tim He Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Michael Kinney Reviewed-by: Jaben Carsey Reviewed-by: Jordan Justen --- MdePkg/Include/Base.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index c666148464..82a773ae74 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -1211,5 +1211,18 @@ typedef UINTN RETURN_STATUS; #define RETURN_ADDRESS(L) ((VOID *) 0) #endif +/** + Return the number of elements in an array. + + @param Array An object of array type. Array is only used as an argument to + the sizeof operator, therefore Array is never evaluated. The + caller is responsible for ensuring that Array's type is not + incomplete; that is, Array must have known constant size. + + @return The number of elements in Array. The result has type UINTN. + +**/ +#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0])) + #endif