Is Visual Studio Compatible with ANSI C Standards?

AI Thread Summary
A user encountered compilation errors while trying to run a simple C program in Visual Studio, questioning whether the issues stemmed from the compiler's adherence to ANSI standards. After troubleshooting, the user found that the errors resolved themselves after creating a new project, suggesting a potential bug in Visual Studio. Another participant recommended ensuring the use of the correct project type and suggested using "int main(int argc, char* argv[])" for empty projects. The original user later discovered that the compilation issues were due to copying and pasting text with non-standard quotation marks from a text source. Additionally, an alternative IDE, Pelles C, was mentioned as a lightweight and effective option for compiling C code.
vociferous
Messages
251
Reaction score
6
I am starting a programing class for scientists and engineers at the end of the month. I wanted to brush up on my C. I used to compile C programs with Visual Studio, but now that no longer seems to work. Even simple example programs in the book generate a litiney of compile errors in Visual Studio (using the Win32 console type application)

For example:

#include <stdio.h>
int main()
{
printf("Goodbye, cruel world!\n");
return(0);
}
generates the following compile errors:

Error 1 error C2065: '"Goodbye' : undeclared identifier c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 2 error C2065: 'cruel' : undeclared identifier c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 3 error C2146: syntax error : missing ')' before identifier 'world' c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 4 error C2017: illegal escape sequence c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11
Error 5 error C2059: syntax error : ')' c:\documents and settings\administrator.minerva.000\my documents\visual studio 2005\projects\goodby world\goodby world\goodby world.cpp 11


Now, I thought that C was supposed to be an ANSI standard and that all C++ compilers were supposed to be able to handle it. Does Visual C++ not conform to that standard or am I just doing something wrong?
 
Technology news on Phys.org
Can you post the entire output of the compiler? Are you sure you're running, say, the C++ compiler, and not the C# compiler?

- Warren
 
I was using visual c++ as a console application and it was generating those errors a couple of days ago. I tried the code on several different projects (regular win32 and win32 consoles) and it refused to compile. When I tried making a new project just a few minutes ago, it compiled and ran perfectly fine. Then I reopened the project that did not compile and it compiled without errors or warnings as well. As far as I know, I did not do anything different, but apparently it is working now. Maybe it was a bug in visual studio, and rebooting fixed it.

Anyway, thanks for your help; I wish I knew what caused the error, but as long as it works now it is of no great concern.
 
TRY adding "int main(int argc, char*argv[])",i believe that's required for empty project. visual studios is kinda picky about certain things...Also make sure you ran a "Win32 console Empty project". If yiour using your own computer try making a shorter directory paths...eg. "C\Code\Projects"
 
Last edited:
After selecting new project, Win32 console, and entering the name, click on application settings, and then click on "empty project".
 
I figured out what the problem was, and it made me feel somewhat stupid. I tried posting examples from a text I was using, and I just cut-and-paste the text into the editor. The compiler did not like the fancy publishing quotation marks.
 
hahahhahahhaha
 

Similar threads

Replies
0
Views
2K
Replies
4
Views
4K
Replies
4
Views
2K
Replies
16
Views
2K
Replies
3
Views
3K
Replies
25
Views
15K
Replies
16
Views
4K
Back
Top