Here are some other ways to declare your struct without needing as much boiler plate per declaration.
#define MAKE_SMARTARRAY(_smartarr, _array) \ do {\ _smartarr.val = (_array);\ _smartarr.len = sizeof((_array))/sizeof((_array[0]));\ }while(0) struct SmartArray { int *val; int len; }; int main() { int array[] = {0,0,0,0}; struct SmartArray arr = {.val = array, .len = sizeof(array)/sizeof(array[0])}; struct SmartArray arr2; struct SmartArray arr3; MAKE_SMARTARRAY(arr2, ((int[]){5,6,7,8})); MAKE_SMARTARRAY(arr3, array); return 0; }
Here are some other ways to declare your struct without needing as much boiler plate per declaration.