How to update all C / C ++ identifier names in a project

After a frequent recommendation not to use leading and double underscores in C / C ++ identifiers, I decided to fix all our sources once and for all. Now I need to convert _Identifierto Identifier_.

Should I use a specialized tool to perform this regular expression task for this job? In the latter case, what is the pattern for matching the C / C ++ identifier?

+5
source share
5 answers

Although I am one of those who often indicate that names with leading underscores can be reserved, I strongly recommend that you do not do this unless you have problems caused by names. Making this global change will make your version control system less useful than otherwise, causing all kinds of false differences. In addition, there is the possibility of creating duplicate names.

In addition, there are many names with an underscore prefix that are completely true. We immediately think about __LINE__, __FILE__etc., as well as all the names of non-standard functions that can be provided to your specific implementation. Filtering these names will be far from trivial (I would say that this is impossible), of course, a simple Perl or sed script will not be enough.

, . , .

+13

Visual Studio, , Visual Assist X, .

+7

Perl , Coccinelle, .

+7

Netbeans , Refactor- > Rename. , , .

+1
source

If your regression tests are strong, then you should have no problem if you just write a quick perl script to replace everything and run the test suite. If you don't have solid regression tests ... well then you can do a perl script replacement and just rebuild the code. If the compilation works, then the chances are pretty good that everything is in order. In other words, try a quick solution and use only a specialized tool if this does not work.

0
source

All Articles