免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: L_kernel

[C] 为什么这样子不报错,或者给一个什么警告也好? [复制链接]

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2011-10-30 19:46 |显示全部楼层
回复  幻の上帝
+UINT_MAX+1,不是+0么?
OwnWaterloo 发表于 2011-10-30 12:40

这句话的意思是:
UINT_MAX+1 的结果就是 0。
+UINT_MAX+1 的结果就是 +0 —— 是"加"0,不是"正"0
既没起到+1的作用,也没起到+UINT_MAX的作用。
—— 于是幻の上帝已经修改了。
ls几位……  在想啥呢……

论坛徽章:
2
青铜圣斗士
日期:2015-11-26 06:15:59数据库技术版块每日发帖之星
日期:2016-07-24 06:20:00
发表于 2011-10-30 19:52 |显示全部楼层
不过既然提到了正负0, 而且MMMIX也给出了一个有符号数可能表示法的wiki链接, 这里就再多说一句。

对某些可能产生正负两种零的有符号数表示法, ISO C是有所准备的。
想想为什么 ISO C只保证short能表示的范围至少有[-32767,+32767] 而非[-32768,+32767] ?
对signed char,int,long也类似。

论坛徽章:
0
发表于 2011-10-30 22:30 |显示全部楼层
回复 32# pmerofc


    第一章标识符下面一小节有讲“标识符的命名空间”

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
发表于 2011-10-30 22:37 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2011-10-31 07:52 |显示全部楼层
大哥,你的kernel真是白学了,而且大学的课程也白上了。

任何一个大学的相关课程中,都会讲补码表示 ...
塑料袋 发表于 2011-10-30 18:59
所以现在要重新捡起来。

论坛徽章:
0
发表于 2011-11-01 09:35 |显示全部楼层
确实很难的东西  搞不懂

论坛徽章:
0
发表于 2011-11-02 22:16 |显示全部楼层
回复 2# OwnWaterloo
好神奇的想法。coding style就是为了防止类似的犯罪吧。

论坛徽章:
0
发表于 2011-11-03 09:53 |显示全部楼层
本帖最后由 狗气球 于 2011-11-03 10:12 编辑
所以现在要重新捡起来。
L_kernel 发表于 2011-10-31 07:52



    别理会塑料袋。信他你就废了。
    “举凡有符号数必补码”←没正经学C很容易有这种看法。

    C标准里对于有符号数的表示给了三种方法。没说非要用补码。

        For signed integer types, the bits of the object representation shall be divided into three
        groups: value bits, padding bits, and the sign bit. There need not be any padding bits;
        there shall be exactly one sign bit. Each bit that is a value bit shall have the same value as
        the same bit in the object representation of the corresponding unsigned type (if there are
        M value bits in the signed type and N in the unsigned type, then M £ N). If the sign bit
        is zero, it shall not affect the resulting value. If the sign bit is one, then the value shall be
        modified in one of the following ways:
        — the corresponding value with sign bit 0 is negated;
        — the sign bit has the value -2N ;
        — the sign bit has the value 1 - 2N

从计算机处理层面上面来讲,不一样吧?
对于有符号数
1000 0000
0000 0000
L_kernel 发表于 2011-10-30 17:57

    你说的这种就是第一种情形“the corresponding value with sign bit 0 is negated;”。
    虽然这种 实现 做法很罕见,也不能说就不可能。
    一般你能看见的C都采用补码,属于第二种情形“the sign bit has the value -2N ;”。

***

    刚写完上面这段,总觉得有啥地方不对劲。
    想想,我说了“实现”俩字儿。
    怎么说,实现一般都会对应到implementation。
    那么就有可能让人觉得我把有符号数表示方法认为是implementation defined了。(虽然仔细推敲并没有这个意思)。
    不是,真不是!{:3_203:}

论坛徽章:
0
发表于 2011-11-03 10:04 |显示全部楼层
这句话的意思是:
UINT_MAX+1 的结果就是 0。
+UINT_MAX+1 的结果就是 +0 —— 是"加"0,不是"正"0 。
既没起到+1的作用,也没起到+UINT_MAX的作用。
—— 于是幻の上帝已经修改了。
ls几位……  在想啥呢……
OwnWaterloo 发表于 2011-10-30 19:46



    看到这里真有一种你吐槽就输了的感觉

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:55:28
发表于 2011-11-03 10:28 |显示全部楼层
不使用typedef后就不能用同名变量了么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP