Error c2143: syntax error: Missing '; 'before '.'

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.