scripting - Perl Script for changing commented llines from c++ to Ansi C style -
i having multiple c source files. in files, comments used in c++ style(i.e //). these want change in c style(/* */). instead of changing manually, there scripts this. if any,let me know, thank full you.
a quick-and-dirty solution sed 's=//\(.*\)$=/*\1 */=
.
this solution not robust because //
may occur inside strings , other comments.
a robust solution needs (partial) c lexical analyzer. however, 1 can argue there no real solution problem because these 2 types of comments incompatible.
consider example http://lua-users.org/lists/lua-l/2013-04/msg00310.html.
int x = 5 //* strange construction */ + 5 + 5;
x
6 in old-style ansi c, 10 if compiler accepts '//' comments.
Comments
Post a Comment