在C99中,如何检查我的结构体是否有成员something
?
#include <stdlib.h>
#include <string.h>
struct some {
char title[50];
char name[50];
};
int main() {
struct some s;
if (*s.something) { // Error: no member named 'something' in 'struct.some'
strcpy(s.something, "Hello");
}
}
更新:
我不需要在编译时知道它是否存在,而是在构建的程序中。成员及其值将从文件中解析,然后在循环中被消耗到结构体中,但我需要确保它将跳过所有不存在的成员。