shirley
shirley

Reputation: 1690

how visual studio tell c++ and c?

As the title says,does the visual studio distinguish these two files by their suffix?.c or .cpp? I also have another question.At first,I stated the program like this:

int main(int argc, char **argv)
{
  LARGE_INTEGER TimeStart;
  LARGE_INTEGER TimeEnd;
  QueryPerformanceCounter(&TimeStart);
  static double Freq;
  static int getfreq; 
  double mu,om;
  double *v;
  int it,i,j;
 ....
}

but it brings out many problems:

1>sor2d.c(23): error C2143: syntax error : missing ';' before 'type'
1>sor2d.c(24): error C2143: syntax error : missing ';' before 'type'
1>sor2d.c(25): error C2143: syntax error : missing ';' before 'type'
1>sor2d.c(26): error C2143: syntax error : missing ';' before 'type'

23 ling points to "static double Freq;" but if I put "QueryPerformanceCounter(&TimeStart);" after the data allocation,the compiler can succeed.Could someone tell me why this happened,was is just because of my carelessness of omitting something or ignorance...?

Upvotes: 0

Views: 230

Answers (2)

kbolino
kbolino

Reputation: 1744

In C89, you must declare all of your variables at the top of the code block. You may also initialize them to compile-time constants (literals, macros that expand to literals, the values of variables that have already been initialized, and any operations on the above that can be performed at compile time). You cannot intersperse other types of statements (like function calls) within these declarations.

This limitation was removed in C99 (which is not supported by Visual C++) and C++.

Upvotes: 0

Joe
Joe

Reputation: 42646

In C, all variables must be declared before calling any methods.

Visual Studio will, by default, compile .C files as C. You can override this.

Upvotes: 1

Related Questions