Syntax error : missing ';' before 'type'

后端 未结 2 1077
野性不改
野性不改 2020-12-30 21:56

So i have this error:

Error 3 error C2143: syntax error : missing \';\' before \'type\' g:\\lel\\tommy\\tommy\\tommy.c 34 tommy

相关标签:
2条回答
  • 2020-12-30 22:32

    Are you compiling with c99 or c89?

    The error appears to be because you are defining a variable within the body of the function (allowed in c99 not c89). Move double *ptr to the beginning of the function and then just assign ptr = mat->matrix; where the error now is.

    0 讨论(0)
  • 2020-12-30 22:39

    When compiling a C program, MSVC doesn't allow declarations to follow statements in a block (it uses old C90 rules - support for declarations mixed with statements was added to C in the 1999 standard).

    Move the declaration of double *ptr to the top of matrix_read():

    int matrix_read(struct matrep *mat, const char *filename)
    {
        FILE *fptr;
        unsigned m, n;
        double *ptr = NULL;
    
        // ...
    
        ptr = mat->matrix;  //this is where the error used to occur
    
        // ...
    }
    

    I really wish MS would implement this 'extension' to their C compiler.

    0 讨论(0)
提交回复
热议问题