Commit 316b4099 authored by Matthias Braun's avatar Matthias Braun
Browse files

array: Return address of elements in ARR_EXTEND(), add ARR_EXTEND1()

parent 96035b37
......@@ -245,11 +245,18 @@ static inline size_t ARR_LEN(void const *const arr)
* @param type The element type of the array.
* @param arr The array, which must be an lvalue.
* @param delta The delta number of elements.
* @return The address of the newly grown elements.
*
* @remark This macro may change arr, so update all references!
*/
#define ARR_EXTEND(type, arr, delta) \
ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
(ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta)), (arr)+ARR_LEN((arr))-(delta))
/**
* Resize a flexible array by growing it by 1 element.
* @return The address of the newly grown element.
*/
#define ARR_EXTEND1(type, arr) ARR_EXTEND(type, (arr), 1)
/**
* Resize a flexible array to hold n elements only if it is currently shorter
......@@ -273,8 +280,7 @@ static inline size_t ARR_LEN(void const *const arr)
* @param arr The array, which must be an lvalue.
* @param elt The new element, must be of type (type).
*/
#define ARR_APP1(type, arr, elt) \
(ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
#define ARR_APP1(type, arr, elt) (*ARR_EXTEND1(type, (arr)) = (elt))
/** @} */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment