Article ID: 181506 - View products that this article applies to.
This article was previously published under Q181506
Microsoft's Visual C++ Integrated Development Environment (IDE) recognizes the following file extensions as C++ source files: .c, .cpp, and .cxx. In some cases, a programmer may want to use other file extensions for C++ files; for example, Unix C++ source files often use the .cc extension.
Using the steps in this article, source files with other file extensions may benefit from the Visual C++ IDE's syntax coloring, automatic indentation, and other usage enhancements. This article describes how to automatically compile such files as C/C++ and associate the C++ icon with these files in Windows Explorer.
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/322756/ )How to back up and restore the registry in Windows
The following procedure causes the Visual C++ IDE to recognize extensions other than .c, .cpp, and .cxx as a C/C++ source file. These changes involve altering registry settings.
To start the Registry Editor:
The following steps apply to keys and values located on the home key. In the Registry Editor, locate the user settings home key for Developer Studio. For various versions, the home key is:
Version 6.0 (ships with Visual Studio 6.0)
Version 5.0 (ships with Visual Studio 97)
The following registry keys cause the IDE to load the C/C++ compiler tool for the specified file extensions (.cc illustrated):
Note External makefiles that are generated from Developer Studio will not have the correct inference rules for new file extensions. Inference rules must be added by either copying existing rules within the makefile (for example, adding SUFFIXES:.cc at the beginning of the makefile and copying the .cpp.obj: rule to create a .cc.obj: rule), or by adding rules in the TOOLS.INI file.
Although the IDE starts the C/C++ compiler tool for the file extensions added in the steps above, the compiler needs to know whether to compile the file as C or C++. The compiler normally compiles .c files as C, and compiles .cpp and .cxx as C++. For all other extensions, the compiler needs an explicit parameter: /TC compiles files as C, /TP compiles files as C++. Each project that includes files with custom extensions needs an explicit /TC or /TP parameter. The following steps illustrate how to do this:
This setting treats ALL source files built by the CL compiler tool in the project as C++ (/TP) or C (/TC) files (the project options cannot be edited on a per-file basis). The entire project now uses either the C++ compiler or the C compiler. To treat individual files in a project as C++ or C source files, use the /Tp<source file> or /Tc<source file> settings. See REFERENCES for more information on the use of compiler settings.
If necessary, a custom build step can launch the C/C++ compiler (CL.EXE) with settings specific to a single file. This is less desirable, because the custom build step requires explicitly listing all of the compiler options. See REFERENCES for online documentation of instructions on adding a custom build step.
Visual C++ Programmer's Guide, Compiling and Linking, Details, Compiler Reference.
Visual C++, Developer Studio Environment User's Guide, Working With Projects, How Do I... Topics: Working With Projects, Customizing a Build Process.
Article ID: 181506 - Last Review: November 2, 2005 - Revision: 4.2
Contact us for more help
Connect with Answer Desk for expert help.