Can I enable C99-style static array sizes in C++ with some GNU extension or whatever?

@alva do you mean like "int array[static 4]" in function sigs or something else
@alva ah

generally GCC extensions are on by default (unless you're passing something like "-std=c++17", in which case you have to change it to e.g. "-std=gnu++17") so if [static] isn't working already, there probably isn't (unless they've implemented it as an __attribute__(()) or [[attribute]] somehow)

@velartrill I was indeed using -std=c++17, but it's still an error with gnu++17. Will check the attributes, thanks. :)
(Making a C API for a heck-library.)

@alva horrible alternative but:

if there isnt an attribute for it, c++ templates are capable of recovering the size of arrays at compile time, and it's possible to specialize a function template such that it will raise a compile-tme error if used with an array that doesn't fit the specified size. it's kind of gnarly, but it's possible
@alva alternately, if the [static] part is for the C headers, you could just write an inline wrapper function in C that then goes on to call the extern C++ wrapper function
@alva or, actually, you don't even need the wrapper. just put the [static] in the C headers and it'll be fine, even if it doesn't match the prototype in C++

@velartrill Yeah, that makes sense. If I hadn't been so lazy, I would have done that already. But instead I was putting it in an extern "C" block while messing around.

Sign in to participate in the conversation
Beach City

Beach City is our private beach-side sanctuary for close friends and awesome folks. We are various flavors of trans, queer, non-binary, polyamorous, disabled, furry, etc.