sa112
sa112

Reputation: 65

C++ file extension in Visual Studio

GNU GCC compiler will compile c++ source files with both .C and.cpp extension.

Is it possible to configure Microsoft Visual Studio so that it could compile the c++ source and header files with extensions .C and .H extension respectively?

Upvotes: 2

Views: 1948

Answers (2)

Adrian McCarthy
Adrian McCarthy

Reputation: 48012

The command line option /TP tells the compiler to treat the source files as C++, even if the extension is something like .c.

In the IDE, you can set this as one of the project properties. Under C/C++, select Advanced Options and set the "Compile As" fields to C++.

Upvotes: 4

Sebastian Redl
Sebastian Redl

Reputation: 72044

The problem is that the Windows file system is not case-sensitive, so there's no difference between .c and .C. This means that the default C language for .c will always apply.

You cannot tell the compiler to generally treat .C files as C++, however you can tell it to treat files in a a compilation command as C++ regardless of their extension with the /TP switch.

Upvotes: 4

Related Questions