我在尝试编译我的单元测试代码时遇到了一个奇怪的错误。出于某种原因,编译器将我的sscanf
调用视为混合声明?我不太明白,这是整个错误:
cc1: warnings being treated as errors
/home/brlcad/brlcad/src/libbn/tests/bn_complex.c: In function 'main':
/home/brlcad/brlcad/src/libbn/tests/bn_complex.c:53: error: ISO C90 forbids mixed declarations and code
make[2]: *** [src/libbn/tests/CMakeFiles/tester_bn_complex.dir/bn_complex.c.o] Error 1
make[1]: *** [src/libbn/tests/CMakeFiles/tester_bn_complex.dir/all] Error 2
make: *** [all] Error 2
int
main(int argc, char *argv[])
{
double expRe1, expIm2, expSqRe1, expSqIm2;
double actRe1, actIm2, actSqRe1, actSqIm2;
actRe1 = actIm2 = actSqRe1 = actSqIm2 =
expRe1 = expIm2 = expSqRe1 = expSqIm2 = 0.0;
bn_complex_t com1,com2; //a struct that holds two doubles
if(argc < 5)
bu_exit(1, "ERROR: Invalid parameters[%s]\n", argv[0]);
sscanf(argv[1], "%lf,%lf", &com1.re, &com1.im); /* Error is HERE */
sscanf(argv[2], "%lf,%lf", &com2.re, &com2.im);
sscanf(argv[3], "%lf,%lf", &expRe1, &expIm2);
sscanf(argv[4], "%lf,%lf", &expSqRe1, &expSqIm2);
test_div(com1, com2, &actRe1, &actIm2);
test_sqrt(com1,com2, &actSqRe1, &actSqIm2);
if((fabs(actRe1 - expRe1) < 0.00001) || (fabs(actIm2 - expIm2) < 0.00001)){
printf("Division failed...\n");
return 1;
}
if((fabs(actSqRe1 - expSqRe1) < 0.00001) || (fabs(actSqIm2 - expSqIm2) < 0.00001)){
printf("Square roots failed...\n");
return 1;
}
return 0;
}