本文介绍了"(无符号)" with long / int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 演员阵容(无符号)暗示(unsigned int),或者它只是简单地 剥离变量的签名? 换句话说,鉴于此: long l = -123; unsigned long ul =(unsigned)l; 是否为' ; 1·;在 分配期间降级为unsigned int,还是保持很长时间? (我在一个系统中, sizeof int == sizeof long,所以检查生成的代码并不是帮助我在这里。) b $ b - + ------------------------- + ------ -------------- + ----------------------- + | Kenneth J. Brody | www.hvcomputer.com | #include | | kenbrody / at\spamcop.net | www.fptech.com | < std_disclaimer.h | + ------------------------- + --------- ----------- + ----------------------- + 不要 - 邮寄给我:< mailto:Th ************* @ gmail.com> 解决方案 Kenneth Brody写道: > 演员表是否(无符号) imply"(unsigned int)", 是。 或者仅仅是 从变量中删除签名? No. 换句话说,鉴于此: long l = -123; unsigned long ul =(unsigned)l; l的值是多少?在 分配期间降级为unsigned int还是保持很长时间? (我在一个系统中 sizeof int = = sizeof long,所以检查生成的代码并不是帮助我。) 分配的类型和值表达式是: ((无符号长)(无符号)-123) - pete Kenneth Brody< ke ****** @ spamcop.netwrites: 演员阵容(无符号) "意味着(unsigned int),或者它只是简单地将b / b从变量中删除? [...] 在演员阵容或任何其他情境中,''unsigned''本身就是 ''unsigned int''的缩写。同样,''long'',''签长'', ''long int''和''signed long int''都是等价的。 参见C99标准第6.7.2节(最新草案可在 < http://www.open-std.org/jtc1/sc22/wg14/www/docs/获取n1124.pdf>,或者在C标准的任何其他版本或草稿中的 对应部分, 或任何体面的C教科书。 - Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst> 圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst> 我们必须做点什么。这是事情。因此,我们必须这样做。 - Antony Jay和Jonathan Lynn,是部长 pete< pf ***** @ mindspring.comwrites: Kenneth Brody写道: [...] >换句话说,鉴于此: long l = -123; unsigned long ul =(unsigned)l; l的值是多少?在任务期间降级为unsigned int还是保持很长时间?(我在一个系统,其中sizeof int == sizeof long,所以检查生成的代码不会''' t 帮帮我。) 赋值表达式的类型和值是: ((unsigned long) (无符号)-123) 实际上,表达式-123的类型为int;转换为未签名的 的操作数是''l'',类型为long。 - Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/ ~kst> 圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst> "我们必须做点什么。这是事情。因此,我们必须这样做。 - Antony Jay和Jonathan Lynn,是部长 Does the cast "(unsigned)" imply "(unsigned int)", or does it simplystrip the signedness from the variable?In other words, given this:long l = -123;unsigned long ul = (unsigned)l;Does the value of "l" get demoted to an unsigned int during theassignment, or does it remain a long? (I am on a system wheresizeof int == sizeof long, so examining the generated code doesn''thelp me out here.)--+-------------------------+--------------------+-----------------------+| Kenneth J. Brody | www.hvcomputer.com | #include || kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|+-------------------------+--------------------+-----------------------+Don''t e-mail me at: <mailto:Th*************@gmail.com> 解决方案 Kenneth Brody wrote:>Does the cast "(unsigned)" imply "(unsigned int)",Yes.or does it simplystrip the signedness from the variable?No.In other words, given this: long l = -123; unsigned long ul = (unsigned)l;Does the value of "l" get demoted to an unsigned int during theassignment or does it remain a long?(I am on a system wheresizeof int == sizeof long, so examining the generated code doesn''thelp me out here.)The type and value of the assignment expression is:((unsigned long)(unsigned)-123)--peteKenneth Brody <ke******@spamcop.netwrites:Does the cast "(unsigned)" imply "(unsigned int)", or does it simplystrip the signedness from the variable?[...]In a cast or in any other context, ''unsigned'' by itself is anabbreviation for ''unsigned int''. Similarly, ''long'', ''signed long'',''long int'', and ''signed long int'' are all equivalent.See section 6.7.2 of the C99 standard (latest draft available at<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf>, or thecorresponding section in any other version or draft of the C standard,or any decent C textbook.--Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>"We must do something. This is something. Therefore, we must do this."-- Antony Jay and Jonathan Lynn, "Yes Minister"pete <pf*****@mindspring.comwrites:Kenneth Brody wrote:[...]>In other words, given this: long l = -123; unsigned long ul = (unsigned)l;Does the value of "l" get demoted to an unsigned int during theassignment or does it remain a long?(I am on a system wheresizeof int == sizeof long, so examining the generated code doesn''thelp me out here.)The type and value of the assignment expression is: ((unsigned long)(unsigned)-123)Actually, the expression ''-123'' is of type int; the operand of thecast to ''unsigned'' is ''l'', which is of type long.--Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>"We must do something. This is something. Therefore, we must do this."-- Antony Jay and Jonathan Lynn, "Yes Minister" 这篇关于"(无符号)" with long / int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-30 15:46