免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3704 | 回复: 10

[C] 请问:这种枚举类型是怎么个意思? [复制链接]

论坛徽章:
0
发表于 2010-12-27 10:18 |显示全部楼层
在Android的源代码里经常看到这样写的枚举类型:
  1. enum {
  2.     kTypeESDS        = 'esds',
  3.     kTypeAVCC        = 'avcc',
  4. };
复制代码
这样写有什么用意吗?
请知道的前辈指点下,谢谢。

论坛徽章:
0
发表于 2010-12-27 11:01 |显示全部楼层
这个还真没见过,C里面肯定是不行的吧

论坛徽章:
0
发表于 2010-12-27 11:35 |显示全部楼层
刚试了下,结果,贴图出来

编译有警告,但是能过去

他赋值是按字符方式赋值的,被当成一个 char型数了,


11.jpg

论坛徽章:
0
发表于 2010-12-27 11:55 |显示全部楼层
之前也见过类似的代码... 难道是and的 呵呵 当java看了...

论坛徽章:
0
发表于 2010-12-27 12:17 |显示全部楼层
恩,三楼的说的有道理

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
发表于 2010-12-27 12:26 |显示全部楼层
'esds' 是一个int类型
当然,其值到底是多少由编译器决定,在C/C++标准中皆未强制规定,所以不具可移植性

论坛徽章:
0
发表于 2010-12-27 13:32 |显示全部楼层
'esds' 是一个int类型
当然,其值到底是多少由编译器决定,在C/C++标准中皆未强制规定,所以不具可移植性
bruceteen 发表于 2010-12-27 12:26



    您好,请问哪本书中有提到类似的:
       'esds' 是一个int类型

    我想了解下,谢谢。

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
发表于 2010-12-27 22:44 |显示全部楼层
摘录自 ISO/IEC 9899:1999(也就是俗称的C99标准文件),第6.4.4.4节(第61页):
10
An integer character constant has type int. The value of an integer character constant
containing a single character that maps to a single-byte execution character is the
numerical value of the representation of the mapped character interpreted as an integer.
The value of an integer character constant containing more than one character (e.g.,
'ab'), or containing a character or escape sequence that does not map to a single-byte
execution character, is implementation-defined.  If an integer character constant contains
a single character or escape sequence, its value is the one that results when an object with
type char whose value is that of the single character or escape sequence is converted to
type int.

重要的就两个,一个是“int”,另一个是“implementation-defined”

论坛徽章:
0
发表于 2010-12-27 23:01 |显示全部楼层
本帖最后由 幻の上帝 于 2010-12-27 23:02 编辑
刚试了下,结果,贴图出来

编译有警告,但是能过去

他赋值是按字符方式赋值的,被当成一个 char型数了 ...
雨夜流星 发表于 2010-12-27 11:35


C里面是窄字符常量int,不是char。
C++里面字面量倒是char。

论坛徽章:
0
发表于 2010-12-27 23:17 |显示全部楼层
C里面是窄字符常量int,不是char。
C++里面字面量倒是char。
幻の上帝 发表于 2010-12-27 23:01



    int a=97
    int a='a'
    char a='a'
    char a=97

  ........
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP