I want to initialize in plain C an array of strings with the following requirements:
(A) I need the strings in a header file, since some other modules are using them as plain strings, so I declared in the header file:
extern const char* const ERRMSG_VM_0001;
extern const char* const ERRMSG_VM_0002;
extern const char* const ERRMSG_VM_0003;
extern const char* const ERRMSG_VM_0004;
and in the source file:
const char* const ERRMSG_VM_0001 = "[VM-001] some text ";
const char* const ERRMSG_VM_0002 = "[VM-002] more text ";
const char* const ERRMSG_VM_0003 = "[VM-003] other text ";
const char* const ERRMSG_VM_0004 = "[VM-003] and even more";
(B) I need these strings also in an array, so I tried in the (same) source (as above):
static const char* error_table[4] =
{
ERRMSG_VM_0001,
ERRMSG_VM_0002,
ERRMSG_VM_0003,
ERRMSG_VM_0004
};
Obviously, the compiler complains error: initializer element is not constant ... so now I am wondering how can I achieve this in a pure C way, not C++ (this is similar to Tricky array Initialization but it's not the same).