ISO C90 forbids mixed declarations and code sscanf

Posted by Need4Sleep on Stack Overflow See other posts from Stack Overflow or by Need4Sleep
Published on 2012-12-14T22:44:07Z Indexed on 2012/12/14 23:03 UTC
Read the original article Hit count: 186

Filed under:

I'm getting a strange error attempting to compile my unit test code,. For some reason the compiler treats my sscanf call as a mixed declaration? I don't quite understand, here is the entire error:

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;
}

© Stack Overflow or respective owner

Related posts about c