我不确定这是否可行,但我需要在运行时修改某些结构的字段。因此,根据运行可执行文件时传递的参数,它应该生成不同类型的结构。
#if (PARAM_SET)
typedef struct{
char fetch[FILE];
uint32_t bin;
uint32_t bin_1;
uint32_t bin_2;
}
HELPER;
typedef struct __attribute__ ((packed)){
char job[4];
uint32_t last;
uint32_t liv_1;
uint32_t liv_2;
uint32_t dipr;
uint32_t notch;
uint32_t cnt;
uint32_t max;
char path[MAX_HEAD_PATH];
HELPER for[MAX_NUM];
}
BOARD;
#else
typedef struct __attribute__ ((packed)){
char job[4]
uint32_t nxt;
uint32_t prv;
uin32 boards;
char path[MAX_NUM];
}
BOARD;
#endif
最佳答案
您无法在运行时(即程序编译后)更改结构。
但是您可以提供两种类型的结构(具有不同的名称)并调整您的代码,以便它根据运行时评估的参数/条件使用正确的类型。
关于c - 在运行时修改结构体字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43926823/