Macro and macro generator for array size inside an array in C.
Only works for C99.
#include <stdio.h>
#include "magicarray.h"
int main() {
const int abcd[] = MAGIC_ARRAY(1, 2, 3, 4, 5, 666, 777, 888, 999);
printf("%li\n", sizeof(abcd) / sizeof(*abcd) - 1);
printf("%li\n", (long) *abcd);
return 0;
}
Should print the same if the MAGIC_ARRAY has a large enough max_size.
Compile arraywizard.c
to arraywizard
for instance.
The following will generate the standard header with max supported size of 255.
./arraywizard > magicarray.h
To generate a header with a larger size:
./arraywizard 1024 > magicarray.h
None: public domain. Do what you want, go to unlicense.org for more info.