Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C99 static array size specifier in C function prototypes #139

Closed
briansmith opened this issue Mar 7, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@briansmith
Copy link
Owner

commented Mar 7, 2016

See https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html

Quoting a comment on that page: "this feature is described in 6.7.6.3 bullet 7, ISO/IEC 9899:201x n1570 working draft."

Instead of writing void foo(int myArray[10]); we should write void foo(int myArray[static 10]); But, this doesn't work in all compilers so we probably need some macro like this:

#if <compiler is known to support it>
#define FIXED_SIZE_ARRAY_PARAM(x, len) x[static len]
#else
#define FIXED_SIZE_ARRAY_PARAM(x, len) x[len]
#endif

and then do something like void foo(int FIXED_SIZE_ARRAY_PARAM(myArray, 10));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.