Write the following two lines of code in the header file:
typedef int X;
typedef int X;
GCC compiler will immediately report redefinition of the TypeDef ' X ', change g++ incredibly nothing, weird it. So to check the document, found in C + + is described in this way: "In a given non-class scope, a typedef specifier can is used to redefine the name of any type declare D in ' scope to ' refer to the ' type to which it already refers. "Well, it does look like C + + for non-class situation tolerance, as the following situation on the error:
Class a{
typedef int Y;
typedef int Y;
};
Unfortunately, in the C language standard find to find, did not see the redefinition of the clear description, not sure if the other C compiler will be an error.
I immediately thought of the macro, so I tried the following three kinds of case:
CASE1: #define M 1
#define M 1
CASE2: #define M (x) x + +
#define M (x) x + +
CASE3: #define M (x) (x+1)
#define M (x) (x + 1)
gcc/g++ compile (should say here is actually preprocessor Cc1/cc1plus) The result is consistent, CASE1/2 OK,CASE3 will error. Checked the criteria, that's how it is described.
(1) Tw o replacement lists are identical if and only if the preprocessing tokens in both have the same number, ordering, s Pelling, and white-space separation, where all white-space separations are considered.
(2) An identifier currently defined as a Object-like macro shall not being redefined by another #define preprocessing direct ive unless the second definition is a Object-like macro definition and the two replacement. Lists are. Likewise, a identifier currently defined as a Function-like macro shall not is redefined by another #define preprocessing directive unless the second definition is a Function-like macro definition, that has the same number and spelling of Param Eters, and the two replacement lists are
Identical.
The key point here is that only when the two words (exactly the same, including whitespace)
Http://hi.baidu.com/zhuxiaoyin/blog/item/f603f58e2e1321e2f11f3656.html