Skip to main content
GameDev.net gamedev.net
🔒 Locked

.c and .cpp files in one visual studio project

Started by AverageJoeSSU Oct 5, 2010 at 12:35 PM 3 replies 1.5k views
Original Post
AverageJoeSSU
AverageJoeSSU
will it compile the the C files as C and the CPP files as C++?

or is there something more i have to do for this to happen? i do not want my .c files compiled as c++.
------------------------------ redwoodpixel.com
Striken
Striken
I think you just need to go to the Project Properties page -> Configuration Properties -> C/C++ -> Advanced and select "Compile as C Code" under the option "Compile As".
Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
Sneftel
Sneftel
Quote:
Original post by AverageJoeSSU
will it compile the the C files as C and the CPP files as C++?
Yes.

Keep in mind that if you have headers that are included by both .c and .cpp files, they may be interpreted differently in the two cases. For safety, any declarations of C functions should be enclosed in a conditional extern "C" block.
frob
frob
Quote:
Original post by Sneftel
For safety, any declarations of C functions should be enclosed in a conditional extern "C" block.
Not just for safety, but for interoperability.

C++ names are mangled, C names are not. The linker will not find matching functions if you don't mark correctly.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.