C语言宏定义-#和##在宏定义中的作用
1. 宏#
#的作用是把宏的标识符进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号
/**
* @def CMO_STRINGIFY
* @brief converts a macro argument into a character constant.
*
* @param[in] x - A macro argument to stringify.
*/
#define CMO_STRINGIFY(x) CMO_STRINGIFY_(x)
/** Auxiliary macro used by @ref CMO_STRINGIFY */
#define CMO_STRINGIFY_(x) #x
2. 宏##
##被称为连接符(concatenator),用来将两个标识符连接为一个标识符
/**
* @def CMO_CONCAT2
* @brief Concatenates two parameters.
*
* It realizes two level expansion to make it sure that all the parameters
* are actually expanded before gluing them together.
*
* @param[in] p1 - First parameter to concatenating
* @param[in] p2 - Second parameter to concatenating
*
* @return Two parameters glued together.
* They have to create correct C mnemonic in other case
* preprocessor error would be generated.
*/
#define CMO_CONCAT2(p1, p2) CMO_CONCAT2_(p1, p2)
/** Auxiliary macro used by @ref CMO_CONCAT2 */
#define CMO_CONCAT2_(p1, p2) p1##p2
/**
* @def CMO_CONCAT3
* @brief Concatenates three parameters.
*
* It realizes two level expansion to make it sure that all the parameters
* are actually expanded before gluing them together.
*
* @param[in] p1 - First parameter to concatenating
* @param[in] p2 - Second parameter to concatenating
* @param[in] p3 - Third parameter to concatenating
*
* @return Three parameters glued together.
* They have to create correct C mnemonic in other case
* preprocessor error would be generated.
*/
#define CMO_CONCAT3(p1, p2, p3) CMO_CONCAT3_(p1, p2, p3)
/** Auxiliary macro used by @ref CMO_CONCAT3 */
#define CMO_CONCAT3_(p1, p2, p3) p1##p2##p3