printf("%p \ n",(void *)0); [英] printf("%p\n", (void *)0);
问题描述
printf("%p \ n",(void *)0); / * UB,还是没有?请解释一下你的答案。 * /
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
推荐答案
infobahn写道:
infobahn wrote:
printf("%p \ n",(void *)0 ); / * UB,还是没有?请解释一下你的答案。
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer.
* /
我认为这个UB标准中没有任何东西。
你没有取消引用一个NULL指针(这是UB),它是这里使用的poitner(地址)的
值。
*/
I don''t think there is anything in the standard that makes this UB.
You are not dereferencing a NULL pointer (which is UB) and it''s the
value of the poitner (address) that is used here.
在文章< 42 *************** @ btinternet.com>,
infobahn< in******@btinternet.com>写道:
:printf("%p\ n",(void *)0); / * UB,还是没有?请解释一下你的答案。 * /
取决于你所说的UB。所有关于
%p的规定都是暗示将打印出来的东西,以及如果使用scanf(%p)读取那么
它返回同一个执行
session然后结果将等于原始指针。
-What-打印未定义 - 它甚至不需要数字。
它可以打印出来自古兰经的诗句...翻译成波斯语...
虽然不可否认你更有可能获得对话片段
$来自吉利根岛的b $ b。
-
熵是概率的对数 - Boltzmann
In article <42***************@btinternet.com>,
infobahn <in******@btinternet.com> wrote:
:printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
Depends what you mean by "UB". All that the standard mandates about
%p is that the implimentation will print -something- out, and that
if scanf("%p") is used to read it back in within the same execution
session then the result will compare equal to the original pointer.
-What- is printed is undefined -- it need not even be numeric.
It could print out verses from the Koran... translated into Farsi...
though admittedly you are more likely to get snippets of dialogue
from "Gilligan''s Island".
--
Entropy is the logarithm of probability -- Boltzmann
infobahn写道:
infobahn wrote:
printf("%p\ n",(void *)0); / * UB,还是没有?请解释一下你的答案。 * /
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
UB,由于缺少printf的原型,并且出现在函数体外的
之外。
-
"如果你想通过groups.google.com发布一个后续内容,请不要使用
破损的" ;回复"链接在文章的底部。点击
" show options"在文章的顶部,然后点击
回复在文章标题的底部。 - Keith Thompson
UB, due to lack of prototype for printf, and appearing outside of
the body of a function.
--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
这篇关于printf("%p \ n",(void *)0);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!