Skip to content

This website works best using cookies which are currently disabled.Cookie policy  Allow cookies
United States of America (English) Change
 

C preprocessor

<tool, programming> (cpp) The standard Unix macro-expansion utility run as the first phase of the C compiler, cc. Cpp interprets lines beginning with "#" such as

#define BUFFER_SIZE 256

as a textual assignment giving the symbol BUFFER_SIZE a value "256". Symbols defined with cpp are traditionally given upper case names to distinguish them from C identifiers. This symbol can be used later in the input, as in

char input_buffer[BUFFER_SIZE];

This use of cpp to name constants, rather than writing these magic numbers inline, makes a program easier to read and maintain, especially if there is more than one occurrence of BUFFER_SIZE all of which must all have the same value.

Cpp macros can have parameters:

#define BIT(n) (1<<(n))

This can be used with any appropriate actual argument:

msb = BIT(nbits-1);

Note the parentheses around the "n" in the definition of BIT. Without these, operator precedence might mean that the expression substituted in place of n might not be interpreted correctly (though the example above would be OK).

Cpp also supports conditional compilation with the use of

#ifdef SYMBOL ... #else ... #endif and #if EXPR ... #else ... #endif

constructs, where SYMBOL is a Cpp symbol which may or may not be defined and EXPR is an arithmetic expression involving only Cpp symbols, constants and C operators which Cpp can evaluate to a constant at compile time.

Decus cpp is a free implementation for VMS.

The most widely used C preprocessor today is the GNU CPP, distributed as part of GCC.

C preprocessor Related Courses

No related courses found

C preprocessor Related Jobs

C/C++ Design Development of POS Applications
Cleveland Ohio, $85,000 - $100,000 based on level and depth of experience Plus includes full benefits package

C/C++ Design Development of POS Applications This Full Time Salary Position requires experience in Creating, Designing and Developing C/C++ More...

C/C++ Developer with VC6 - RO1-Reno-VC6
Sparks NV, $85k - $120k

C/C++ Developer with Visual C++ 6.0 - C/C++, VC 6.0, Casino Game C/C++ Developer with Optima If you are a C/C++ Developer with experience More...

C/C++ Developer - SA1-CC DEVELOPER
San Francisco CA, $60k - $130k

C/C++ Developer - C, C++, Python C/C++ Developer If you are a C/C++ Developer with experience, please read on! We are an exciting, THRIVING More...

C/C++ Software Architect - RS-Engineer
Hillsborough CA, $120k - $150k

C/C++ Software Architect - C/C++, PERL, PHP C/C++ Software Architect Headquartered in the San Mateo area, we are a rapidly growing More...

C/C++ Linux Software Engineer
Huntsville AL

C/C++ Linux Software Engineer (Job Number:318151) Description: SAIC has a position open for a Software Developer to support CORE Software More...