Skip to content

jansegre/magicarray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

magicarray

Macro and macro generator for array size inside an array in C.

Only works for C99.

Using the macro

#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.

Generating a macro

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

License

None: public domain. Do what you want, go to unlicense.org for more info.

About

Macro and macro generator for array size inside an array in C.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages