无符号的字符 * [英] unsigned char *
问题描述
#include< stdio.h>
int main(无效)
{
long dword = 0xff;
printf("%u \ n",((unsigned char *)& dword)[0]);
返回0;
}
标准说这是合法的吗?
如果是,或者如果没有,是什么部分?
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", ((unsigned char *)&dword)[0]);
return 0;
}
does the standard say this is legal?
if so or if not, what section?
推荐答案
在''comp.lang.c''中, j0 ** **** @ engineer.com (j0mbolar)写道:
In ''comp.lang.c'', j0******@engineer.com (j0mbolar) wrote:
#include< stdio.h>
int main(void)
{d /> long dword = 0xff;
printf("%u \ n",((unsigned char *)& dword)[0]);
返回0;
}
标准是否说这是合法的?
如果是,或者如果没有,是什么部分?
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", ((unsigned char *)&dword)[0]);
return 0;
}
does the standard say this is legal?
if so or if not, what section?
>
否。无符号字符将转换为int,但%u想要一个未签名的
int。行为未定义。
#include< stdio.h>
int main(无效)
{
long dword = 0xff;
printf("%u \ n",(unsigned)((unsigned char *)& dword) [0]);
返回0;
}
-
-ed-收到我的电子邮件: http://marreduspam.com/ad672570
C语言常见问题解答: http:// www .eskimo.com / ~scs / C-faq / top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de fclc: http://www.isty-info.uvsq。 fr / ~rumeau / fclc /
No. An unsigned char will be converted to an int, but "%u" wants an unsigned
int. The behaviour is undefined.
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", (unsigned) ((unsigned char *)&dword)[0]);
return 0;
}
--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
2004年6月29日格林威治标准时间10:00:49, Emmanuel Delahaye< em ********** @ noos.fr>
在comp.lang.c中写道:
On 29 Jun 2004 10:00:49 GMT, Emmanuel Delahaye <em**********@noos.fr>
wrote in comp.lang.c:
In' 'comp.lang.c'', j0******@engineer.com (j0mbolar)写道:< br>
In ''comp.lang.c'', j0******@engineer.com (j0mbolar) wrote:
#include< stdio.h>
int main(无效)
{长龙= 0xff;
printf("%u \ n",((unsigned char *)& dword)[0]);
返回0;
}
该标准是否合法?
如果是,或者如果没有,那么哪个部分?
否。无符号字符将被转换为int,但是%u想要一个未签名的
int。行为是未定义的。
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", ((unsigned char *)&dword)[0]);
return 0;
}
does the standard say this is legal?
if so or if not, what section?
No. An unsigned char will be converted to an int, but "%u" wants an unsigned
int. The behaviour is undefined.
unsigned char将在许多平台上转换为signed int,
但是对于某些sizeof的unsigned int (int)== 1.有这样的
平台,主要是数字信号处理器和一些奇特的RISC
架构。您可能没有遇到过它们,但我会定期处理它们
。
因此,如果代码是在这样的平台上编译的(例如TI 2812) DSP
我目前正在处理),结果已经完美定义。
#include< stdio.h>
int main(void )
{long / long = 0xff;
printf("%u \ n",(unsigned)((unsigned char *)& dword)[0] );
返回0;
}
An unsigned char will be converted to signed int on many platforms,
but to unsigned int on some where sizeof(int) == 1. There are such
platforms, mostly Digital Signal Processors and some exotic RISC
architectures. You may not have encountered them, but I work on them
regularly.
So if the code is compiled on such a platform (such as the TI 2812 DSP
I am working on currently), the result is perfectly defined.
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", (unsigned) ((unsigned char *)&dword)[0]);
return 0;
}
当然上面的便携性更高。
-
Jack Klein
主页: http ://JK-Technology.Com
常见问题解答
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c ++ http://www.parashift。 COM / C ++ - FAQ-精简版/
alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Of course the above is much more portable.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
2004年6月29日02:27:50 -0700, j0 ****** @ engineer.com (j0mbolar)在comp.lang.c中写了
:
On 29 Jun 2004 02:27:50 -0700, j0******@engineer.com (j0mbolar) wrote
in comp.lang.c:
#include< stdio.h>
int main(无效)
{长/长= 0xff;
printf("%u \ n",((unsigned char *)& dword)[0]);
返回0;
}
标准是否说这是合法的?
如果是,或者如果没有,是什么部分?
#include <stdio.h>
int main(void)
{
long dword = 0xff;
printf("%u\n", ((unsigned char *)&dword)[0]);
return 0;
}
does the standard say this is legal?
if so or if not, what section?
这是不合法的,除了在sizeof(int)== 1的平台上,并且
是其中一些但不在桌面上世界。
在大多数常见的实现中,signed int可以保存所有可能的无符号字符的
值,因此值为c转换为签名int,而不是
unsigned int其中%u转换说明符需要。
C标准建议有符号和无符号整数类型应该是函数调用中可以接受的替换,但是
保证就是这样。
-
Jack Klein
主页: http://JK-Technology.Com
常见问题解答
comp.lang.c http:// www。 eskimo.com/~scs/C-faq/top.html
comp.lang.c ++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn。 c-c ++
http: //www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
It is not legal except on platforms where sizeof(int) == 1, and there
are some of those but not in the desk top world.
In most common implementations, signed int can hold all possible
values of unsigned char, so the value is converted to signed int, not
unsigned int which the "%u" conversion specifier requires.
The C standard suggests that signed and unsigned integer types should
be acceptable substitutions for each other in function calls, but does
guarantee that this is so.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
这篇关于无符号的字符 *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!