Handling extensionless C++ header files

It has become vogue in recent times to use extensionless header files. I think it started with the STL library and spread, like a virus, from there.   Oops… sorry to inject my personal opinon there. Suffice to say, I think they are a bad idea.

But they are a reality and we have to deal with them.  In fact, we have hundreds of them in our own source tree, courtesy our use of Qt for GUI portability.

As a teaching example, I setup an Understand project file that includes the Qt include tree.  I added a “Makefile” to it for example – it wasn’t really there to start with.  But it does highlight the problem and gives a clue as to why I, a static analysis tool vendor, don’t like extensionless header files…. How are we supposed to tell Makefile, or Todo, or Readme from QString.  Sure we could analyze them to see what was in them, but that is a pain and error prone.

But there is a way, and here is how.

First off, when adding a directory I have to have an additional file filter of *:

2008-05-16 07.32

This places them in the Project, but as un-parsed files:

2008-05-13 20.432008-05-13 20.46

So how do I get QAbstractFileEngine to parse, but not Makefile?

First, I have to tell Understand’s project configuration that extensionless files map to C++. I do this in Project->Configure, File Types:

2008-05-13 20.48

It seems counter-intuitive but go ahead and leave it empty – this adds <none> as a file type:

2008-05-13 20.49

Okay, so now all extensionless files will be treated as C++.  Unfortunately, Makefile will be as well.

But that is easily remedied. There are two approaches. The first is to browse to the file and remove it from the project in Project->Configure->Files

2008-05-13 20.51

Or more generically to remove the pattern “Makefile” from the project. But for now, just exclude them like by configuring the overide settings on the project (click on 25 2008-05-13 20.54 ):

2008-05-13 20.55

A Rescan happens and kindly informs you that a file was removed:

2008-05-13 20.56

Hit Okay, accept the reparse and you are off to the races:

2008-05-13 20.57

 

If you would like to do this same thing from the command line, the commands are as follows:

und -db project.udb settings -Filetypes .=c++

Now to remove the makefile files use:

und add -exclude “makefile” c:\path\to\directory