The following error occurs when compiling the c file:
Error c2143: syntax error: Missing '; 'before' type'
But there is no error in the CPP file. TestCodeAs follows:
# Include "stdafx. H"
# Include "cv. H"
# Include <stdio. h>
Int _ tmain (INT argc, _ tchar * argv [])
{
Cvmat * MAT = cvcreatemat (3, 3, cv_32fc1 );
Cvzero (MAT); // sets the Matrix to 0.
// Cv_mat_elem (* mat, float, 2, 0) = 11.0;
Cvmset (MAT, 11.0 );
Float f_elem;
// F_elem = cv_mat_elem (* mat, float, 2, 0 );
F_elem = cvmget (MAT, 2, 0 );
Printf ("% F", f_elem );
Return 0;
}
In the c file, declare the statement
Float f_elem;
Put at the beginning, that is, before cvmat * MAT = cvcreatemat (3, 3, cv_32fc1.
This problem occurs when C ++ is compiled by VC.ProgramOr GCC does not appear when compiling the C program. It only appears when Vc compiles the C program.
In the C program, the variable is placed before calling a function (or executing an operation. (Do not know whether the so-called c89 standard is used)
Recently, I found a problem when writing a program. Compiling C language with VC always prompts an error: Error c2143: syntax error: Missing '; 'before' type '. After a long time, I had no answer, so I searched online and finally found a solution in a netizen's blog. The solution is as follows:
Put the declaration of all variables before the executable code.
This problem occurs because the file is saved in *. c format. If it is in CPP format, it can be compiled normally.
This is because: in ansi c or C ++, it is allowed to define variables in executable code at any time, but it is not allowed in K & r c, therefore, this error occurs. Vc6.0 and vs2008 use K & r c to implement C language. Therefore, an error is reported during compilation.