Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What effect does #define X X have in C?

In the source code of stdbool.h in LLVM project, it reads:

/* Don't define bool, true, and false in C++, except as a GNU extension. */
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool, bool, false, true as a GNU extension. */
#define _Bool bool
#define bool  bool
#define false false
#define true  true
#endif

In the last 4 lines there are three lines of the from #define X X. Why would you do that? What difference does it make? Wouldn't this force compiler to just replace, say, true with true?

like image 836
Mohsen Nosratinia Avatar asked Sep 01 '13 11:09

Mohsen Nosratinia


People also ask

How does this effect or affect me?

Here is a basic guideline for affect or effect that can help clarify how to use the two words correctly: Generally, we use affect as a verb (an action word) and effect as a noun (an object word).

How do you use affect and effect in a sentence?

Affect is usually a verb meaning "to produce an effect upon," as in "the weather affected his mood." Effect is usually a noun meaning "a change that results when something is done or happens," as in "computers have had a huge effect on our lives." There are exceptions, but if you think of affect as a verb and effect as ...

Does affect mean impact?

Affect is most often used as a verb meaning “to have an impact on,” as in “The tornado barreling towards us will affect our picnic plans.” Continue reading...


1 Answers

The only reason I can think of is, that preprocessor statements like

#ifdef bool
// do some stuff or define bool
#endif

in other c files include afterwards will work proper and not trying to redefine bool in another way like

#define bool int

which would interfere with the first definition

like image 178
Martin Schlott Avatar answered Oct 08 '22 13:10

Martin Schlott