Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a C++ preprocessor identical to a C preprocessor?

I am wondering how different the preprocessors for C++ and C are.

The reason for the question is this question on a preprocessor-specific question where the paragraph of the standard that addresses the question has a different wording (and a different paragraph number) and also are difference concerning the true and false keywords in C++.

So, are there more differences or is this the only difference.

An extension of the question would be when is a source file emitted differently by a C++ preprocessor and a C preprocessor.

like image 311
René Nyffenegger Avatar asked Feb 23 '11 00:02

René Nyffenegger


People also ask

Is preprocessor and preprocessor directives are same?

Preprocessor directives, such as #define and #ifdef , are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions.

What is C preprocessor and write C program to describe different Preprocessors?

The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.

What do you mean by C preprocessor?

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

What are the types of C preprocessor?

There are 4 Main Types of Preprocessor Directives:Macros. File Inclusion. Conditional Compilation. Other directives.


2 Answers

The C++03 preprocessor is (at least intended to be) similar to the C preprocessor before C99. Although the wording and paragraph numbers are slightly different, the only technical differences I'm aware of between the two are that the C++ preprocessor handles digraphs and universal character names, which are not present in C.

As of C99, the C preprocessor added some new capabilities (e.g., variadic macros) that do not exist in the current version of C++. I don't remember for sure, but don't believe that digraphs were added.

I believe C++0x will bring the two in line again (at least that's the intent). Again, the paragraph numbers and wording won't be identical, but I believe the intent is that they should work the same (other than retaining the differences mentioned above).

like image 132
Jerry Coffin Avatar answered Sep 22 '22 19:09

Jerry Coffin


They are supposed to be the same: C++98 and C++03 should match C90, and C++0x should match C99. There may be bugs in the wording, though.

like image 32
Jeremiah Willcock Avatar answered Sep 20 '22 19:09

Jeremiah Willcock