1. # difference between define and typedef
# Define is generally used to define constants and statement macro definitions and act as macro replacement during compilation. Of course, you can also complete a small part of the typedef function. Remember that it is only a small part.
Typedef is used to declare a new type name for readability and variable definition.
Example 1:
# Define int // No semicolon !!
Typedef int; // remember that there is no # Before typedef, and this statement is required. The semicolon ends.
In this example, int num; can be implemented in this way, basically no difference.
Example 2:
# Define pint int *
Typedef int * pint;
There is a difference in this example. We need to define int * a, * B; Use define to implement pint a, B; replace int * a, B; it defines pointer A and variable B. In typedef usage, pint A and B define pointer variable A and pointer variable B.
Therefore, typedef must be used to declare a new type name for security purposes.
2. # define, # If defined (), # ifndef, # ifdef, # else # elseif # endif
A) # define defines constants. For example, # define debug indicates that debug has been defined.
B) # If defined (Debug), if there is only one condition, it is equivalent to # ifdef debug
Therefore, # If defined () is often used in multi-condition environments. You can use "|, &,!" in the middle of multiple conditions ,&&,!" For example, # If defined (ebug) & defined (win32)
This means that when both Debug and Win32 are defined, the statement under the # If condition is entered.
C) # ifdef If debug is defined, execute the statement under the # ifdef condition. Its intention and # ifndef debug
On the contrary, N in the middle indicates that there is no meaning, that is, if there is no definition ....
D) # endif pairing # If pairing
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/fangjuntan/archive/2009/06/07/4248861.aspx