6

I know that C preprocessor exists as part of compiler. But I'm looking for an independent program. Is there any such tool?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
claws
  • 52,236
  • 58
  • 146
  • 195

6 Answers6

11

It's often called cpp. For example, on my Linux box:


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

This particular one is part of gcc and is available for a wide variety of platforms.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
4

mcpp.

From the homepage:

mcpp is a C/C++ preprocessor with the following features.

  • Implements all of C90, C99 and C++98 specifications.
  • Provides a validation suite to test C/C++ preprocessor's conformance and quality comprehensively. When this validation suite is applied, mcpp distinguishes itself among many existing preprocessors.
  • Has plentiful and on-target diagnostics to check all the preprocessing problems such as latent bug or lack of portability in source code.
  • Has #pragma directives to output debugging information.
  • Is portable and has been ported to many compiler-systems, including GCC and Visual C++, on UNIX-like systems and Windows.
  • Has various behavior modes.
  • Can be built either as a compiler-specific preprocessor to replace the resident preprocessor of a particular compiler system, or as a compiler-independent command, or >even as a subroutine called from some other main program.
  • Provides comprehensive documents both in Japanese and in English.
  • Is an open source software released under BSD-style-license.
knarf
  • 2,672
  • 3
  • 26
  • 31
4

You can also have a look at m4

What is m4?

M4 can be called a “template language”, a “macro language” or a “preprocessor language”. The name “m4” also refers to the program which processes texts in this language: this “preprocessor” or “macro processor” takes as input an m4 template and sends this to the output, after acting on any embedded directives, called macros.

epatel
  • 45,805
  • 17
  • 110
  • 144
3

I've used filepp for preprocessing files other than straight C. It's a Perl module, so it's pretty portable. It's handy in that you can use all the familiar idioms you are used to, and adds some useful features.

From the web site:

Why filepp and not plain old cpp?

cpp is designed specifically to generate output for the C compiler. Yes, you can use any file type with it, but the output it creates includes loads of blank lines and lines of the style:

# 1 "file.c"

Obviously these lines are very useful to the C-compiler, but no use in say an HTML file. Also, as filepp is written in Perl, it is 8-bit clean and so works on any character set, not just ASCII characters. filepp is also customisable and hopefully more user friendly than cpp.

Glenn McAllister
  • 1,813
  • 17
  • 14
  • 2
    Note that most compilers, such as GCC, have something like a -P switch which omits the generation of linemarkers in the output from the preprocessor. – Wiz Jan 04 '14 at 08:32
1

cpp is just one. It's a separated program called by gcc when compiling.

Ryan Li
  • 9,020
  • 7
  • 33
  • 62
1

It is a part of the package, and usually called cpp (C PreProcessor).

which cpp
# /usr/bin/cpp
man cpp
khachik
  • 28,112
  • 9
  • 59
  • 94