I’ve just started using Visual Studio (I got VS 2012 from dreamspark, and it hasn’t been long since I’ve started using Windows again) and I’m having some trouble.
I have a single file named “main.c” under my Source Files folder that looks like this:
#include <stdio.h>
typedef struct S_s S;
struct S_s {
void* x;
};
int main(int argc, char** argv)
{
int N;
scanf("%d", &N);
S* s;
printf("%p", s);
return 0;
}
And when I try to build it gives me the following error messages:
Error 3 error C2065: 's' : undeclared identifier c:\users\math4tots\documents\visual studio 2012\projects\algorithms\lecture1\main.c 13 1 Lecture1
Error 4 error C2065: 's' : undeclared identifier c:\users\math4tots\documents\visual studio 2012\projects\algorithms\lecture1\main.c 14 1 Lecture1
Error 2 error C2275: 'S' : illegal use of this type as an expression c:\users\math4tots\documents\visual studio 2012\projects\algorithms\lecture1\main.c 13 1 Lecture1
The funny thing is that it builds just fine if I comment out the scanf line.
I did create an “Empty project” under the “Visual C++” options so I wasn’t sure if VS compiled it as a C or C++ program. However, I was under the impression that my code was C/C++ agnostic enough that it should compile in either C or C++.
What can I do to get this to build while still maintaining the semantics of the program?
The code is legal C++ and legal C99, but not legal C89. Variable declarations in C89 must come at the beginning of a block, so having
S* s;afterscanf("%d", &N);
is not OK in C89.