Just wrap a structure around it?
struct Char32 {
char data[32];
};
void func(Char32 ¶m) { ... };
Just wrap a structure around it?
struct Char32 {
char data[32];
};
void func(Char32 ¶m) { ... };
In this case the size is known, so you don't need the template:The syntax for array passing is crazy in C++ but this will do allow you to do this:
I highly recommend you use a template on the array parameter here because this function now works with any sized arrays.template <size_t charCount> void stringCopy(char (&output)[charCount], const char* source) { }
void stringCopy(char (&output)[32], const char* source)
{
}
But I still recommend using std::array.
This goes a little bit off-topic, but I recently found this: https://docs.google.com/presentation/d/1h49gY3TSiayLMXYmRMaAEMl05FaJ-Z6jDOWOz3EsqqQ/preview?slide=id.gcfd0be4a_20
According to that, you should be able to statically enforce passed array sizes to have at least 32 entries by writing:
void func(char param[static 32])
{
}
However, I wasn't able to reproduce the compiler warning when passing an array with a smaller size. I'm using GCC 4.9.3 with these options:
gcc -W -Wall -Wextra -pedantic -o test main.c
It appears to be a feature of C, not C++ (http://stackoverflow.com/questions/3430315/purpose-of-static-keyword-in-array-parameter-of-function)