Console C++ - .cxx File Extension

The acccepted standard file extension for c++ source files is .cpp. I don't understand why teachers require their students to use .cxx. The only purpose I see is to confuse the PC based compilers.

The problem here is that the dos/windows compilers automatically assume that files ending in .c or .cpp are source files. As a result, they automatically know to compile the files.

Another problem is related to syntax highlighting and the editors built-in help. It is generally useful to have comments and strings highlighted. (When I was learning to program, one of my common problems was to accidentally comment out half of the program when I meant to only remove a few lines. Sometimes, I forgot the final double quote on a string. Syntax highlighting helps to prevent this type of problem.)

I guess that you might be a better programmer if you learn on the dumbest compiler/editor combination available. But I see no reason to make programming more difficult than necessary.

Borland C++ | Visual C++ | GNU g++ (Unix)


Borland C++ 5.02

With Borland C++ 5.02, you need to make 2 changes to use the .cxx extension.


Project Definition

To compile an application made of several source files, you can either The "best" way to do this is to use a Project definition. (In may ways, this is similar to a graphical representaion of a traditional makefile.)

To create a project, from the menu, select

and set the following parameters Using the Advanced button, select No Source Node and disable both checkboxes. (Close all dialog boxes using positive responses.) At this point, a new project (.ide file) is created and a tree view is displayed in the Project window.

Now you can highlight the exe node and right click to add a new node (source file). Using this, you can add any existing source file or create a .cpp file. You can NOT create a .cxx file this way. I use notepad to create empty cxx files and then add them.

You should also add the header (.h) files to your project. They are not required to compile the project, but, once added, the nodes can be double clicked in order to view their source. (Double clicking the .exe node will compile and execute it.)


Handling Unknown Node Types

By default, Borland C++ 5.02 does not recognize the .cxx extension and, therefore, will not display or compile those files. There are 2 solutions
  1. Tell the compiler to treat that node like it was a .cpp file

    This procedure must be followed for each .cxx file in your project. However, once it is done once, these definitions are remembered in the .ide (project) file. When you want to re-open your project, be sure to open the ide file and not the individual source files.

  2. Teach the compiler how to handle .cxx files

    Once this is done, it applies to all future projects.


Editor - Syntax Highlighting

In order to add Syntax Highlighting to unknown file types, from the menu, select add whatever extension you want to the Syntax Extensions data entry field. The syntax is fairly obvious - just add to the end of the existing text.

Once made, this change is remembered and it applies to all furture projects.


Microsoft Visual C++


GNU g++ (Unix)

Well, file extension are not really a problem here - there are NO source file defaults. In the makefile, you are required to explicitly provide what ever extension you want. As far as Syntax Highlighting - forget it. There are a few editors that support this, but pico does not. If you work in an X-window, you will have more options.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Console_C++ / cxx.html