a.cpp:
static const struct A {
int a1;
const char ** a2;
} as[] = {
{1,(const char *[]){"LOL",NULL}开发者_如何学Python},
{2,(const char *[]){"LOL","LOL2",NULL}}
};
const char ** getA(int a) {
int i = 0;
for(;i< sizeof(as)/sizeof(struct A);i++){
if (as[i].a1 == a)
return as[i].a2;
}
}
Is there a context or scope problem in returning const char **
from a static const struct initialized statically?
There's certainly no scope problem. Scope pertains to variables, not to values. (There is a problem with missing {
in your code, though.)
No, that is fine - compound literals that occur outside the body of a function have static storage duration.
You're trying to put a variable sized array of pointers into a fixed size struct. That can't be good.
精彩评论