代码中的任何错误 [英] any error in the code

查看:41
本文介绍了代码中的任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()

{

int * p;

p =(int *)malloc(sizeof(int));

if(p == NULL)

{

错误(无法分配内存\ n);

错误(退出.... \ n);

退出(1);

}

是检查gcc是否正确,(与NULL比较)

int main()
{
int *p;
p = (int*)malloc(sizeof(int));
if(p == NULL)
{
Error("Could not allocate the memory\n");
Error("Quitting....\n");
exit(1);
}
Is it correct to check in gcc , ( compare with NULL )

推荐答案

文章< 65 ************ *@mid.individual.net>,

Martin Ambuhl< ma ***** @ earthlink.netwrote:
In article <65*************@mid.individual.net>,
Martin Ambuhl <ma*****@earthlink.netwrote:

> pa********@hotmail.com写道:
>pa********@hotmail.com wrote:

> int main()
{*> int * p;
p =(int *)malloc(sizeof(int));
if(p == NULL)
{
错误(无法分配内存\ n);
错误(退出.... \ n);
退出(1);
}

签入gcc是否正确,(与NULL比较)
> int main()
{
int *p;
p = (int*)malloc(sizeof(int));
if(p == NULL)
{
Error("Could not allocate the memory\n");
Error("Quitting....\n");
exit(1);
}
Is it correct to check in gcc , ( compare with NULL )


您的程序以多种方式破解。使用gcc
或使用C语言的任何其他编译器都不正确。将其与以下内容进行比较:


Your program is broken in oh-so-many ways. It is not correct with gcc
or with any other compiler for C. Compare it to the following:



伟大的Antonious Twink。知道所有。告诉所有人。

The great Antonious Twink. Knows all. Tells all.


4月1日,2:47 * pm,parag_p ... @ hotmail.com < parag_p ... @ hotmail.com>

写道:
On Apr 1, 2:47*pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:

* int main()

* {

* * * int * p;

* * * p =(int *)malloc(sizeof(int));
* int main()
* {
* * * int *p;
* * * p = (int*)malloc(sizeof(int));



不要输入cast malloc作为C标准状态。

Do not type cast malloc as the C standard states.


* * * if(p == NULL)

* * * {

* * * * *错误(无法分配内存\ n);

* * * * *错误(退出.... \ n);

* * * * *退出(1);

* * *}


签入gcc是否正确,(与NULL比较)
* * * if(p == NULL)
* * * {
* * * * * Error("Could not allocate the memory\n");
* * * * * Error("Quitting....\n");
* * * * * exit(1);
* * * }

Is it correct to check in gcc , ( compare with NULL )



在退出

计划之前总是释放动态分配的内存


~Jack

--------------------------------------
http://programmingsite.googlepages.com

Always free the dynamically allocated memory before exitting from the
program

~Jack
--------------------------------------
http://programmingsite.googlepages.com


Ja ************* @gmail。 com 说:

4月1日下午2:47,parag_p ... @ hotmail.com < parag_p ... @ hotmail.com>

写道:
On Apr 1, 2:47 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:

> int main()
{
int * p;
p =(int *)malloc(sizeof(int));
>int main()
{
int *p;
p = (int*)malloc(sizeof(int));



不要输入cast malloc作为C标准状态。

Do not type cast malloc as the C standard states.



C标准并未说出要转换malloc返回的值,要么不要说b $ b不要转换该值。


转换malloc返回的值是没有意义的,可以隐藏bug,但

既不是禁止也不是强制性的。


更重要的是,如果你*必须*为某些

愚蠢的理由施放malloc的结果,请确保你#include< stdlib.h>,因为(在C90中)

cast删除了您的实施义务,以诊断症状

未能包含该标题。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

The C Standard does not say either to cast the value returned by malloc, or
not to cast that value.

Casting the value returned by malloc is pointless and can hide a bug, but
it is neither forbidden nor compulsory.

Rather more importantly, if you *must* cast the result of malloc for some
silly reason, make sure that you #include <stdlib.h>, because (in C90) the
cast removes the obligation on your implementation to diagnose a symptom
of failing to include that header.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于代码中的任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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