今天闲逛Linux宝库,看到论坛里有人在讨论如何用 shell 脚本来处理 C 语言注释,发帖时间是 08-10-23(以前怎么都没注意到,失败...),但问题好像并没被解决。正好这两天玩 sed & awk,来小试一下身手。 C语句注释 本文讨论的是 C99 标准,它支持单行注释(“// ...”)和块注释(“/*...*/”),并且当单行注释以“/”结尾时也可以跨多行。测试代码如下: #include <stdlib.h> #include <stdio.h> int main (int argc, char *argv[]) { // not show/ not show/ not show // not show /* not show */ int is; // not show int/* not show */ ms; /* not show */ double ds; // not show/ not show/ not show double dm; /* ... not show not show */ float fs; /** * now show */ float/**/ fm; char cs[] = "aaa // /***/"; char cm1[] =