首页 > 编程知识 正文

c语言 Switch,C语言switch语句

时间:2023-05-06 11:15:28 阅读:155655 作者:4100

C语言的宏观定义分析

导游词:你懂c语言吗? 你知道c语言的宏观定义是什么吗? 以下是网络编辑与大家分享的C语言“宏观定义分析,请阅读。

在c语言中,预处理程序功能:

1 .替换1. #include or ' '的头文件

2.#define对象替换(object-like ) ) ) ) ) ) ) ) )。

对象替换在第一个空格处被拆分,然后是替换主题列表

3.#define ()函数替换(function-like ) ) ) ) )。

函数替换()之间不能包含空格。 但是,中间可以有空间。

替换函数时,必须注意参数表的优先级和类型。 在替换块中输入--';' 如果需要,请用do{}while(0)打包,然后单击,

另外,在宏观定义的末尾加上“; 请注意没有”。 否则,在if-else语句时容易出错。

条件编译选项,如4 #ifdefine

在宏的定义中容易出错的是##和#的使用。

#连接两个参数,

#definemycase(item,id ) () ) ) ) )。

case id:

item##_##id=id;

布莱克

switch(x ) (

我的主页(构件,23 );

}

我的主页(构件,23 ); 扩展为

case 23:

构件_ 23=23;

布雷克;

#是将参数转换为字符串

#definequoteme(x ) #x

printf(%s(n ),quoteme ) )1);

置换后==

printf('%s(n ),'1)2);

使用##和#时,如果宏的一定参数也想替换为宏(使用该值)

必须使用间接访问的方法,而不是参数名称。

有以下两个例子。

------------- -请参阅

enum {

OlderSmall=0,

NewerLarge=1

(;

#define Older Newer

# define小型标签

#define_replace_1(older,Small ) Older##Small

#define_replace_2(older,Small ) _ replace _1(older,Small ) )。

语音打印(语音)。

{

//_replace_1(older,Small ) becomesoldersmall ) notnewerlarge )、

//despite the #define calls above。

printf(check1:%d(n ),_replace_1) older,Small );

//theparametersto _ replace _2aresubstitutedbeforethecall

//to _replace_1,so we get NewerLarge。

printf(check2:%d(n ),_replace_2) older,Small );

}

results is:

检查1: 0

检查2: 1

------------- -请参阅

#define FOO bar

#define QUOTEME_(x ) #x

#definequoteme(x ) QUOTEME_(x ) x ) )。

the code

printf(foo=%s(n ),quoteme ) foo );

扩展后==

printf(foo=%s(n ),) bar );

【c语言宏观定义分析】相关文章:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。