如何检查我的结构something在 C99 中是否有成员?
#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");
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
我不需要知道它在编译时是否存在,而是在构建的程序中。成员及其值将从文件中解析,然后在循环中消耗到结构中,但我需要确保它会跳过所有不存在的成员。