c – 多字符恒定警告

weixin_38068653 2019-09-12 10:10:09
为什么这是一个警告?我认为在很多情况下使用multi-char int常量而不是“无意义”数字或者使用相同值定义const变量更为明确.解析wave / tiff /其他文件类型时,可以更清楚地将读取值与某些“EVAW”,“数据”等进行比较,而不是相应的值. 示例代码: int waveHeader = 'EVAW'; 为什么这会发出警告?
...全文
105 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38069804 2019-09-12
  • 打赏
  • 举报
回复
According to the standard(§6.4.4.4/ 10) The value of an integer character constant containing more than one character (e.g., ‘ab’), […] is implementation-defined. long x = '\xde\xad\xbe\xef'; // yes, single quotes 这是有效的ISO 9899:2011 C.它在没有警告的情况下使用-Wall编译gcc,并且使用-pedallic编译“多字符字符常量”警告. 从Wikipedia开始: Multi-character constants (e.g. ‘xy’) are valid, although rarely useful — they let one store several characters in an integer (e.g. 4 ASCII characters can fit in a 32-bit integer, 8 in a 64-bit one). Since the order in which the characters are packed into one int is not specified, portable use of multi-character constants is difficult. 为了便于携带,请不要使用带有整数类型的多字符常量.

473

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧