C语言宏定义#与##

C语言宏定义#与##

  • “#” 字符串化

#include <stdio.h>

typedef struct os_thread_def  {
  char            *name;        ///< Thread name
  int             pthread;      ///< start address of thread function
  int             tpriority;    ///< initial thread priority
  int             instances;    ///< maximum number of instances of that thread function
  int             stacksize;    ///< stack size requirements in bytes; 0 is default stack size
} osThreadDef_t;

#define osThreadDef(name, thread, priority, instances, stacksz)  \
const osThreadDef_t os_thread_def_##name = \
// #name 将变为name字符串
{ #name, (thread), (priority), (instances), (stacksz)}


int main()
{
	osThreadDef(defaultTask, 0, 0, 0, 128);
	printf("%s\n",os_thread_def_defaultTask.name);

    return 0;
}

  • “##” 标识符拼接
#define TEST(x)  i##x

TEST(2) 相当于 i2

更多精彩内容,请关注微信公众号“边缘智能实验室”

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/jiasike/article/details/107450068
今日推荐