0%

源码中移除注释

怎样从C工程中移除注释以及#if 0代码

  1. GCC
  2. unifdef
  3. sunifdef
  4. scc-snapshots

GCC preprocesse

gcc -fpreprocessed -dD -E app_test.c
  • -fpreprocessed Indicate to the preprocessor that the input file has already been preprocessed.
  • -dD Dump all macro definitions, at the end of preprocessing, in addition to normal output.
  • -E the linker is not run

scc-snapshots

scc-snapshots

$ sunifdef -DDEFINED -ned < app_test.c > 2.c

unifdef

unifdef

sunifdef

sunifdef

Ref

  1. GCC几个选项学习
  2. Remove comments from C/C++ code
  3. scc-snapshots
  4. Remove code between #if 0 and #endif when exporting a C file to a new one