Is following array initialization correct? I guess it is, but i’m not really sure if i can use const char* or if i better should use std::string. Beside the first question, do the char pointers point to memory segments of same sizes?
struct qinfo
{
const char* name;
int nr;
};
qinfo queues[] = {
{"QALARM", 1},
{"QTESTLONGNAME", 2},
{"QTEST2", 3},
{"QIEC", 4}
};
Yes, that looks fine. Obviously you won’t be able to subsequently modify any of the name strings (although you can change the pointers to point at different strings if you need to). Storage for each of the const strings will be only as much as is needed and will typically be read-only.