Add ARRAY_INIT_VALUE
This commit is contained in:
1 parent
9c2468c2b7
commit
f8b4f44105
3 files changed
+27
No files matched your search
@@ -1479,6 +1479,20 @@ are provided.
|
||||
Return the oplist of the array defined by calling ARRAY\_DEF with name & oplist.
|
||||
If there is no given oplist, the default oplist for standard C type is used.
|
||||
|
||||
#### ARRAY\_INIT\_VALUE()
|
||||
|
||||
Define an initial value that is suitable to initialize global variable(s)
|
||||
of the type associated to the (array) oplist 'oplist'.
|
||||
It enables to create an array as a global variable and to initialize it.
|
||||
|
||||
The array should still be cleared manually to avoid leaking memory.
|
||||
|
||||
Example:
|
||||
|
||||
ARRAY_DEF(array_int_t, int)
|
||||
array_int_t my_array = ARRAY_INIT_VALUE();
|
||||
|
||||
|
||||
#### Created methods
|
||||
|
||||
In the following methods, name stands for the name given to the macro.
|
||||
|
||||
@@ -53,6 +53,12 @@
|
||||
(__VA_ARGS__ )))
|
||||
|
||||
|
||||
/* Define an init value to init global variables of type array.
|
||||
USAGE:
|
||||
array_t global_variable = ARRAY_INIT_VALUE(array_oplist);
|
||||
*/
|
||||
#define ARRAY_INIT_VALUE() \
|
||||
{ { 0, 0, NULL } }
|
||||
|
||||
/********************************************************************************/
|
||||
/********************************** INTERNAL ************************************/
|
||||
|
||||
@@ -41,6 +41,8 @@ ARRAY_DEF(array_ulong, uint64_t)
|
||||
ARRAY_DEF_AS(array_double, ArrayDouble, ArrayDoubleIt, double)
|
||||
#define M_OPL_ArrayDouble() ARRAY_OPLIST(array_double, M_DEFAULT_OPLIST)
|
||||
|
||||
ArrayDouble g_array = ARRAY_INIT_VALUE();
|
||||
|
||||
static void test_uint(void)
|
||||
{
|
||||
array_uint_t v;
|
||||
@@ -362,6 +364,11 @@ static void test_double(void)
|
||||
ref += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
assert( array_double_empty_p(g_array));
|
||||
array_double_push_back(g_array, 34.);
|
||||
assert( array_double_size(g_array) == 1);
|
||||
array_double_clear(g_array);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
Reference in new issue
Block a user