Using C in vs 2005

Started by
5 comments, last by Pouya 17 years, 4 months ago
Hi guys, Im writing some code for a robot project in C. Sadly our robot hasnt shipped yet so I have to program it without and visualize the results. Has to be in C and Id like to use MFC dialogs for the output. 1. What exactly cant I use in my vs 2005 dev environment to make sure Im sticking to plain C. No classes, no std, malloc/free anything else? 2. Will just naming my files *.c make the compiler interpret the code as c and thus give me errors when using c++? Thanks guys -CProgrammer
Advertisement
1. Indeed no classes, no std. Malloc and free are useable, but new and delete aren't. Variable declarations need to be done at the top of the function.
2. Go to Configuration Properties -> C/C++ -> Advanced, then change the Compile As option to 'Compile as C code (/TC)'.

Don't know if you can use MFC in plain C (I think not), so I'd make two projects: a static plain-C library containing your robot code, and a C++-MFC application that does the visualization and links to the C-code. But that might have been your plan all along [smile].
Thanks the c compile function is great.

O my god, no functions in structs. Arg the pain.

Does that mean the best way is to have all member functions declared global and taking teh struct as param? Oh my...
Quote:Original post by DaBono
Don't know if you can use MFC in plain C (I think not)
Indeed. MFC stands for Microsoft Foundation Classes and it's C++ only.
0) Exactly how much has to be in C, and why?
1) There are quite a few differences between the languages, many of which are not commonly mentioned.
MSVC defaults to looking at the file extension to to figure out what language you're using, so yes just naming it .c is enough in the vast majority of cases. If it's named .cpp, .cxx, or a few others then it will compile as C++.

The switch DaBono mentioned is there for wierd cases or for those people who absolutely positivitely want to be 100% double-sure.
-Mike
Quote:Original post by Zahlman
0) Exactly how much has to be in C, and why?
I'm guessing because it's an embedded application (the robot), he probably won't have A) any support libraries, B) a high level compiler

This topic is closed to new replies.

Advertisement