C预处理器库

5

我有一个任务是为C程序开发源代码分析工具,需要在分析之前对代码进行预处理。我想知道哪个库最适合这个任务。我需要一个轻量级且便携的库。

1个回答

5

不要自己开发,为什么不使用gcc套件中的cpp工具:http://gcc.gnu.org/onlinedocs/gcc-4.6.1/cpp/

CPP(1)                                GNU                               CPP(1)

NAME
       cpp - The C Preprocessor

SYNOPSIS
       cpp [-Dmacro[=defn]...] [-Umacro]
           [-Idir...] [-iquotedir...]
           [-Wwarn...]
           [-M|-MM] [-MG] [-MF filename]
           [-MP] [-MQ target...]
           [-MT target...]
           [-P] [-fno-working-directory]
           [-x language] [-std=standard]
           infile outfile

       Only the most useful options are listed here; see below for the
       remainder.

DESCRIPTION
       The C preprocessor, often known as cpp, is a macro processor that is
       used automatically by the C compiler to transform your program before
       compilation.  It is called a macro processor because it allows you to
       define macros, which are brief abbreviations for longer constructs.

这也是我的基本想法,但我在想是否有任何不使用 cpp 的方法来实现它。 - Kijan
我想知道为什么你需要在不使用“cpp”的情况下完成它。也就是说,针对你提出的问题已经存在一个成熟的解决方案。那个解决方案有什么不足之处? - Brian Gerard
我只是想知道是否有其他比cpp更高效的方法来完成它。不过,由于其可移植性,我可能会使用cpp - Kijan
@Kijan,你在你的cpp代码中发现了哪个部分效率低下? - sigjuice
不管效率如何,将C预处理器作为一个库从另一个应用程序内部使用是一种合法的用例。假设我获得了一个C文件缓冲区,并且想要对其进行预处理。将其写入文件并调用命令行工具的方法过于繁琐。 - Jordan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接