问题来源:在读marlin程序时遇到这种表达,对于我C语言菜鸟来说瞬间懵逼,上网查了下,恍然大悟,现总结如下。
/// set pin as input
#define _SET_INPUT(IO) do {DIO ## IO ## _DDR &= ~MASK(DIO ## IO ## _PIN); } while (0)
/// set pin as output
#define _SET_OUTPUT(IO) do {DIO ## IO ## _DDR |= MASK(DIO ## IO ## _PIN); } while (0)
#表示将后面的宏参数进行字符串化。
##表示连接前后两个变量(符号)。
下面的代码表达的比较清楚:
#include <iostream>
void quit_command(){
printf("I am quit command\n");
}
void help_command(){
printf("I am help command\n");
}
struct command
{
char * name;
void (*function) (void);
};
#define COMMAND(NAME) {#NAME,NAME##_command}
#define PRINT(NAME) printf("token"#NAME"=%d\n", token##NAME)
main(){
int token9=9;
PRINT(9);
struct command commands[] = {
COMMAND(quit),
COMMAND(help),
};
commands[0].function();
}
输出为:
token9=9
I am quit command
参考:
2.http://blog.csdn.net/ce123/article/details/8961518
3.http://gcc.gnu.org/onlinedocs/cpp/Stringification.html