Changing Comments from C++ style to C style

Unfortunately most scripts will only work the other way around. There is a decent one named "RECOMMENT" but it takes C and converts to the newer C++ style comments. I imagine your reason for wanting to do this is due to compiler errors with the C++ style comments. The usual cause of this is a line that uses a C-style comment with an C++ style comment. Perhaps looking for that particular scenario would eliminate your need to convert back to older style commenting. If not, sadly you might have to do it by hand. (I pray that you don't as I know how tedious that can be!)


Recomment Link: http://people.sc.fsu.edu/~jburkardt/cpp_src/recomment/recomment.html

A substitution with you favorite editor and a regular expression like s#//(.*)#/*\1 */# should do it...


You can do this with the Vim plugin Nerdcommenter.

This makes it easy to uncomment the text and then add a multi-line comment like you want.


If you are looking for something a little more generic, you could also use a source code formatting tool for this. For C, I've used uncrustify before and it worked reasonably well. There may be others as well, but I think uncrustify can change C++ style comments into C style comments with the cmt_cpp_to_c parameter.

The configuration can be a little daunting, but if you just use the example config file and change only the stuff you are interested in, it might do what you want.

Tags:

C

Comments