I want to initialize a local char array with a string, which is generated to a static const pointer. Basically it looks like this:
static const char * const FOO = "foo"; /* generated */
char bar[12] = FOO; /* my code */
The compiler does not accept it:
error: array must be initialized with a brace-enclosed initializer
What construct can I use to initialize the char array bar with the string pointed to by FOO?
Context: in my company, we write unit testers for C code using a C++ framework. Therefore the bar parameter must be an array and cannot be a C++ string type. The FOO constant is generated from a proprietary IDL. The code generator generates a #define for C code, but a static const char * const for C++.
char bar[12]; strcpy(bar, FOO);?Assert(sizeof bar > strlen(FOO));to the test code. And thereafterstrcpy(bar, FOO);. This makes your tester more robust agains changes in the generated code.