利用宏定义##,简洁的定义几个类似的函数,方法如下例所示:
struct led_attr{
struct attribute attr;
ssize_t(*show)(char*);
ssize_t(*store)(const char *, size_t count);
};
#define glow_show_led(number) \
static ssize_t glow_led_##number(const char buffer,size_t count)\
{\
}\
static ssize_t show_led_##number()\
{\
}\
static struct led_attr led##number = \
__ATTR(led##number, 0644, show_led_##number, glow_led_##number);
接下来定义几个函数:
glow_show_led(0);
glow_show_led(1);
glow_show_led(2);
......
这里的##number中的##表示连接的作用,比如glow_show_led(0)这个宏,number是0,所以也就是glow_led_0(....)...
阅读(687) | 评论(0) | 转发(0) |