关于指针的动态分配 [英] regarding dynamic allocation for pointers

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

问题描述

大家好,

我刚刚从我的一个朋友那里听说,当指针未初始化时,很少有c编译器会发出错误空值。这是正确的吗?

如果是的话,有什么标准吗?


提前致谢...

Hi Everyone,

I just heard from a friend of mine that there are few c compilers that
give an error when pointers are not initialised to NULL. Is it correct?
and if so, is there any standard for that?

Thanks in advance...

推荐答案

sa ***** @ yahoo.co.in 写道:

大家好,


我刚刚从我的一个朋友那里听说c编译器很少

指针未初始化为NULL时发出错误。这是正确的吗?

如果是的话,有什么标准吗?


提前致谢...
Hi Everyone,

I just heard from a friend of mine that there are few c compilers that
give an error when pointers are not initialised to NULL. Is it correct?
and if so, is there any standard for that?

Thanks in advance...



不正确。标准中没有要求任何指针是由程序员初始化为NULL的
。如果标准希望新的

指针为NULL,则编译器会执行此操作。文件范围内的静态指针

例如。


-

Joe Wright

"一切都应尽可能简单,但并不简单。

---阿尔伯特爱因斯坦---

Incorrect. There is no requirement in the Standard that any pointer be
initialized to NULL by the programmer. If the Standard wants a new
pointer to be NULL, the compiler does it. Static pointers at file scope
for example.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


2007年1月6日05:08:24 -0800, sa*****@yahoo.co.in 写道:
On 6 Jan 2007 05:08:24 -0800, sa*****@yahoo.co.in wrote:

>大家好,


我刚从我的一个朋友那里听说,很少有c编译器可以给你指针未初始化为NULL时的错误。这是正确的吗?
如果是的话,那有什么标准吗?
>Hi Everyone,

I just heard from a friend of mine that there are few c compilers that
give an error when pointers are not initialised to NULL. Is it correct?
and if so, is there any standard for that?



你真的是指错误还是它实际上只是一个警告。 />

不幸的是,该标准并未禁止诊断

非错误代码。该标准也没有区分

信息性消息,警告消息,错误消息等。

因此,除了所需的诊断(例如,
$) b $ b约束违规),编译器编写者可以根据需要添加任意和

。它变成了实现问题的质量。


标准确实要求编译器接受正确的程序

即使它发布了可选的诊断程序。


有些编译器会智能地使用这种灵活性,例如检查

对转换说明符的printf参数类型和

报告不匹配。其他人,在我看来,过火了(如在

原帖中)并且显然做得不一致(为什么不在指针之外标记其他

未初始化的对象)。

删除电子邮件的del

Did you really mean error or is it actually just a warning.

Unfortunately, the standard does not prohibit diagnostics for
non-erroneous code. The standard also does not distinguish between
informational messages, warning messages, error messages, etc.
Consequently, in addition to the required diagnostics (e.g.,
constraint violations), the compiler writer is allowed to add any and
as many additional ones as he wants. It becomes a quality of
implementation issue.

The standard does require the compiler to accept a correct program
even if it issued optional diagnostics.

Some compilers use this flexibility intelligently, such as checking
the types of printf arguments against the conversion specifiers and
reporting mismatches. Others, in my opinion, go overboard (as in the
original post) and apparently do so inconsistently (why not flag other
uninitialized objects besides pointers).
Remove del for email


sa **** *@yahoo.co.in 写道:

大家好,


我刚从朋友那里听到我指出,当指针未初始化为NULL时,很少有c编译器

给出错误。这是正确的吗?

如果是的话,有什么标准吗?


提前谢谢...
Hi Everyone,

I just heard from a friend of mine that there are few c compilers that
give an error when pointers are not initialised to NULL. Is it correct?
and if so, is there any standard for that?

Thanks in advance...



任何自尊的编译器*都不应该为

uinitialised指针发出错误。我不认为该标准禁止发布

诊断(但这比错误更有用)。但是

编译器必然会编译一个正确的翻译单元。

Any self-respecting compiler *shouldn''t* emit an error for an
uinitialised pointer. I don''t think the standard prohibits issuing a
diagnostic, (which would be more useful than an error), though. However
a compiler is bound to compile a correct translation unit.


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

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