0
我与-Wdeclaration-after-statement
编译,我得到以下警告:声明结构,以避免混合声明和代码
ISO C90 forbids mixed declarations and code
这是因为我需要填充阵列之前执行某些操作。
我不知道什么是一种好的方法或替代方案来初始化和声明cars
,所以这个警告可以避免。
有问题的代码看起来是这样的:
int my_func() {
typedef struct Car_ {
char *brand;
int amount;
int color;
} Car;
int fixed = 0;
int total1 = getAmountBase(brand1);
int total2 = getAmountSub(brand2);
int total3 = getAmountBase(brand3);
int total4 = getAmountSub(brand4);
int grand = getAmountBase(brand7);
// more operations...
if (grand7 != NULL) {
grand7 = calcBase(grand7, total6);
fixed = addGrand(grand7);
}
Car cars[] = { // warning here.
{"brand1", total1, RED},
{"brand2", total2, RED},
{"brand3", total3, RED},
{"brand4", total4, RED},
{"brand7", fixed, RED},
};
// ...
}
太棒了。谢谢! – user1024718