打印NULL指针 [英] Printing a NULL pointer

查看:111
本文介绍了打印NULL指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个不使用所有位0表示

一个NULL指针的实现。让NULL指针由0x12345678表示。

在这样的实现中,如果打印了NULL指针的值

将全部为0'或0x12345678


int main(无效)

{


char * ptr;

ptr = 0;


printf(" \ nptr =%p \ n",ptr);

}


输出是什么,0或0x12345678?

我认为用户必须保持透明内部表示

的NULL指针。即使使用0x12345678为NULL指针实现

,打印的值应该全部为

位零。

Consider an implementation that doesn''t use all bits 0 to represent
a NULL pointer. Let the NULL pointer is represented by 0x12345678.
On such an implementation, if the value of NULL pointer is printed
will it be all 0''s or 0x12345678

int main(void)
{

char *ptr;
ptr = 0;

printf("\nptr=%p\n",ptr);
}

What would be the output, 0 or 0x12345678 ?
I think user must be kept transparent from the internal representation
of NULL pointer. Even if the implementation is
using 0x12345678 for NULL pointer, value printed should be all
bits zero.

推荐答案

>考虑一个不使用所有位0表示
>Consider an implementation that doesn''t use all bits 0 to represent
NULL指针的实现。让NULL指针由0x12345678表示。
在这样的实现中,如果打印出NULL指针的值,它将全部为0'或0x12345678


可能。它也可以打印为(ullnay)。

输出是什么,0或0x12345678?


在某些实现中很可能%p

的输出总是包含冒号。

我认为用户必须从NULL指针的内部表示保持透明。


如果那是你的意见,那很好。我不认为这是合理的

标准或实现者共享。

即使实现是使用0x12345678进行NULL指针,值打印应该是全部
位零。
a NULL pointer. Let the NULL pointer is represented by 0x12345678.
On such an implementation, if the value of NULL pointer is printed
will it be all 0''s or 0x12345678
Probably. It could just as well be printed as "(ullnay)".
What would be the output, 0 or 0x12345678 ?
It is quite possible on some implementations that the output of %p
always contains a colon.
I think user must be kept transparent from the internal representation
of NULL pointer.
If that''s your opinion, fine. I don''t think this is justified
by the standard or shared by implementors.
Even if the implementation is
using 0x12345678 for NULL pointer, value printed should be all
bits zero.




Gordon L. Burditt



Gordon L. Burditt


6月14日星期二2005 22:50:26 -0700,junky_fellow写道:
On Tue, 14 Jun 2005 22:50:26 -0700, junky_fellow wrote:
考虑一个不使用所有位0来表示空指针的实现。让NULL指针由0x12345678表示。
在这样的实现中,如果打印出NULL指针的值,它将全部为0'或0x12345678


两者或两者都不。实现可以输出它,例如,

例如,< null>

int main(无效)


char * ptr;
ptr = 0;

printf(" \ nptr =%p \ n",ptr);
}
}

标准没有指定%p的输出形式。没有

要求它采用十六进制数字的形式,虽然它可以和

一些实现这样做。

我认为用户必须保持从NULL指针的内部表示透明。


这当然不是必需的。所需要的只是scanf()

%p可以从printf的输出重新创建指针()%p

即使
实现正在使用0x12345678为NULL指针,值打印
应该全部为零。
Consider an implementation that doesn''t use all bits 0 to represent
a NULL pointer. Let the NULL pointer is represented by 0x12345678.
On such an implementation, if the value of NULL pointer is printed
will it be all 0''s or 0x12345678
Either or neither. The implementation could coose to output it as, for
example, <null>
int main(void)
{

char *ptr;
ptr = 0;

printf("\nptr=%p\n",ptr);
}
}
What would be the output, 0 or 0x12345678 ?
The standard does not specify the form of output of %p. There is no
requirement that it takes the form of a hex number, although it can and
some implementations do that.
I think user must be kept
transparent from the internal representation of NULL pointer.
That is certainly not a requirement. All that is required is that scanf()
%p can recreate the pointer from the output of printf() %p
Even if
the implementation is using 0x12345678 for NULL pointer, value printed
should be all bits zero.




如果你想要完全透明,那么直接对应任何特定的
$ b应避免$ b位模式。


劳伦斯



If you want full transparency then direct correspondance to any particular
bit pattern should be avoided.

Lawrence




Le 15/06/2005 07:50,dans
11 *** ******************@g47g2000cwa.googlegroups.c om

?* ju ********* *@yahoo.co.in*? <菊********** @ yahoo.co.in> aécrit*:

Le 15/06/2005 07:50, dans
11*********************@g47g2000cwa.googlegroups.c om,
?*ju**********@yahoo.co.in*? <ju**********@yahoo.co.in> a écrit*:
考虑一个不使用所有位0来表示空指针的实现。让NULL指针由0x12345678表示。
在这样的实现中,如果打印空指针的值将是全部0'或0x12345678
int main (无效)
{

char * ptr;
ptr = 0;

printf(" \ nptr =%p \ n" ,ptr);
}

什么是输出,0或0x12345678?
我认为用户必须保持透明,以免NULL指针的内部表示。即使实现是使用0x12345678作为NULL指针,打印的值应该全部为零位。
Consider an implementation that doesn''t use all bits 0 to represent
a NULL pointer. Let the NULL pointer is represented by 0x12345678.
On such an implementation, if the value of NULL pointer is printed
will it be all 0''s or 0x12345678

int main(void)
{

char *ptr;
ptr = 0;

printf("\nptr=%p\n",ptr);
}

What would be the output, 0 or 0x12345678 ?
I think user must be kept transparent from the internal representation
of NULL pointer. Even if the implementation is
using 0x12345678 for NULL pointer, value printed should be all
bits zero.




如果0是一个似乎很危险有效地址,如果0x12345678为NULL,则可能是
。在那个cas中,我更喜欢0x12345678,

甚至是(null)。或任何明确宣布空指针的内容。



It seems dangerous if 0 is a valid address, and it probably will be
if 0x12345678 is NULL. In that cas, I would prefer 0x12345678,
or even "(null)" or anything clearly announcing a NULL pointer.


这篇关于打印NULL指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆