有沒有一種簡便的方法可以在不進行任何預處理的情況下從C / C ++源文件中刪除注釋。(即,我認為您可以使用gcc -E,但這會擴展宏。)我只希望除去注釋的源代碼,沒有其他更改。編輯:偏愛現(xiàn)有工具。我不想自己用正則表達式編寫代碼,我預見代碼中會出現(xiàn)太多驚喜。
3 回答

鴻蒙傳說
TA貢獻1865條經(jīng)驗 獲得超7個贊
在您的源文件上運行以下命令:
gcc -fpreprocessed -dD -E test.c
感謝KennyTM找到正確的標志。這是完整性的結果:
test.c:
#define foo bar
foo foo foo
#ifdef foo
#undef foo
#define foo baz
#endif
foo foo
/* comments? comments. */
// c++ style comments
gcc -fpreprocessed -dD -E test.c:
#define foo bar
foo foo foo
#ifdef foo
#undef foo
#define foo baz
#endif
foo foo
- 3 回答
- 0 關注
- 848 瀏覽
添加回答
舉報
0/150
提交
取消