免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2784 | 回复: 16
打印 上一主题 下一主题

[C] 请教C语言中的宏 [复制链接]

论坛徽章:
5
2015年迎新春徽章
日期:2015-03-04 09:58:1115-16赛季CBA联赛之上海
日期:2016-01-18 13:24:3015-16赛季CBA联赛之佛山
日期:2016-01-27 10:13:0515-16赛季CBA联赛之北控
日期:2016-08-04 22:33:2115-16赛季CBA联赛之山西
日期:2016-08-06 15:49:33
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-06 09:14 |只看该作者 |倒序浏览
C里宏中如果出现了强转,

  1. #define N ((unsigned char) 8)

  2. #if (N == 8)
  3. ...
  4. #endif
复制代码
这样用就会出现编译错误,
请问为啥会这样?

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
2 [报告]
发表于 2013-01-06 09:43 |只看该作者
本帖最后由 cokeboL 于 2013-01-06 09:44 编辑

回复 1# __slucx__
  1. #if (N == 8)

  2. 改成

  3. #if equal(N, 8)

  4. “==”应该是语言本身的,不是预编译指令,你在#if 的预编译里用当然不认识

复制代码

论坛徽章:
0
3 [报告]
发表于 2013-01-06 09:55 |只看该作者
预编译应该不能识别类型转换吧
求#if值的时候遇到unsigned char会报错

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
4 [报告]
发表于 2013-01-06 11:18 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
5 [报告]
发表于 2013-01-06 11:25 |只看该作者
pmerofc 发表于 2013-01-06 11:18
回复 1# __slucx__


C11 又冒出来了,我咋还在看C89,极度 out 呀!

论坛徽章:
5
2015年迎新春徽章
日期:2015-03-04 09:58:1115-16赛季CBA联赛之上海
日期:2016-01-18 13:24:3015-16赛季CBA联赛之佛山
日期:2016-01-27 10:13:0515-16赛季CBA联赛之北控
日期:2016-08-04 22:33:2115-16赛季CBA联赛之山西
日期:2016-08-06 15:49:33
6 [报告]
发表于 2013-01-06 11:31 |只看该作者
谢谢各位
C11 又冒出来了,我咋还在看C89


话说我木有看过C标准

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
7 [报告]
发表于 2013-01-06 11:36 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
8 [报告]
发表于 2013-01-06 11:59 |只看该作者
C++11:

After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers and keywords, except for true and false, are replaced with the pp-number 0, and then each preprocessing token is converted into a token. The resulting tokens comprise the controlling constant expression which is evaluated according to the rules of 5.19 (常量表达式) using arithmetic that has at least the ranges specified in 18.3 (数字限定). For the purposes of this token conversion and evaluation all signed and unsigned integer types act as if they have the same representation as, respectively, intmax_t or uintmax_t (18.4).

论坛徽章:
1
巨蟹座
日期:2014-03-18 23:44:30
9 [报告]
发表于 2013-01-07 10:15 |只看该作者
pmerofc 发表于 2013-01-06 11:36
回复 5# socay2


现在实际编程中用 C11 或 C99 多不?

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
10 [报告]
发表于 2013-01-07 19:11 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP