Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Tell HN: C Experts Panel – Ask us anything about C. Parent comment
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; }
There are no comments on this comment yet.
Here are some other ways to declare your struct without needing as much boiler plate per declaration.