From b6a539c8d57e49b43ef9889717039fa2204e57a8 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 29 Mar 2019 15:31:28 -0700 Subject: [PATCH] [code-utils] add OT_ARRAY_END() macro (#3722) This commit adds `OT_ARRAY_END(aArray)` macro which returns a pointer to the end of a given array (pointing to the past-the-end element). --- src/core/common/code_utils.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/common/code_utils.hpp b/src/core/common/code_utils.hpp index 118f1a0ae..2c32aca60 100644 --- a/src/core/common/code_utils.hpp +++ b/src/core/common/code_utils.hpp @@ -49,6 +49,19 @@ */ #define OT_ARRAY_LENGTH(aArray) (sizeof(aArray) / sizeof(aArray[0])) +/** + * This macro returns a pointer to end of a given array (pointing to the past-the-end element). + * + * Note that the past-the-end element is a theoretical element that would follow the last element in the array. It does + * not point to an actual element in array, and thus should not be dereferenced. + * + * @param[in] Name of the array variable + * + * @returns Pointer to the past-the-end element. + * + */ +#define OT_ARRAY_END(aArray) (&aArray[OT_ARRAY_LENGTH(aArray)]) + /** * This macro returns a pointer aligned by @p aAlignment. *