转换malloc()的返回值? [英] Casting the return value of malloc() ?

查看:81
本文介绍了转换malloc()的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我经常想知道是否施放malloc()(或

朋友)的返回值实际上有帮助,最近的线程在这里建议它是

不...所以我希望能找到答案。


例如:


char * tmp = NULL;


tmp =(char *)malloc(1024);


是否有任何指向强制转换malloc的返回值?我看到

很多人这样做,但没有测试结果,如:


if(tmp ==(char *)NULL)

..关于malloc()失败的一些代码...


投下它有什么意义吗?


干杯,

--Tim

Hi,

I have often wondered if casting the return value of malloc() (or
friends) actually helps anything, recent threads here suggest that it
does not .. so I hope to find out.

For instance :

char *tmp = NULL;

tmp = (char *) malloc(1024);

Is there any pointing in casting the return value of malloc? I see
many people do that, but not test the result such as :

if (tmp == (char *) NULL)
.. some code about malloc() failing ...

Is there any point in casting it?

Cheers,
--Tim

推荐答案

Tinkertim写道:
Tinkertim wrote:
$ b $


我经常想知道是否施放malloc()(或

朋友)的返回值实际上有什么帮助,最近的线程在这里暗示它

不..所以我希望能找到答案。


例如:


char * tmp = NULL;


tmp =(char *)malloc(1024);


是否有任何指向转换malloc的返回值?
Hi,

I have often wondered if casting the return value of malloc() (or
friends) actually helps anything, recent threads here suggest that it
does not .. so I hope to find out.

For instance :

char *tmp = NULL;

tmp = (char *) malloc(1024);

Is there any pointing in casting the return value of malloc?



无所不知。


-

Ian Collins。

None what so ever.

--
Ian Collins.


文章< 7c ********************************** @ p49g2000hsd。 googlegroups.com>,

Tinkertim< ti ******* @ gmail.comwrote:
In article <7c**********************************@p49g2000hsd. googlegroups.com>,
Tinkertim <ti*******@gmail.comwrote:

>

我经常想知道是否施放malloc()(或朋友)的返回值实际上有什么帮助,最近的线程在这里暗示它不会......所以我希望找出。
>Hi,

I have often wondered if casting the return value of malloc() (or
friends) actually helps anything, recent threads here suggest that it
does not .. so I hope to find out.



很高兴看到我们回到了熟悉的地方。

Good to see we''re back on familiar ground.


Tinkertim说:
Tinkertim said:




我经常想知道是否要转换malloc()的返回值(或

朋友)实际上有帮助,
Hi,

I have often wondered if casting the return value of malloc() (or
friends) actually helps anything,



您认为它提供了哪些帮助?我不能想到任何。

What help do you think it offers? I can''t think of any.


最近的帖子在这里暗示它

不...所以我希望能找到答案。


例如:


char * tmp = NULL;


tmp =(char * )malloc(1024);


是否有任何指向转换malloc的返回值?
recent threads here suggest that it
does not .. so I hope to find out.

For instance :

char *tmp = NULL;

tmp = (char *) malloc(1024);

Is there any pointing in casting the return value of malloc?



对我来说似乎完全没有意义。你有什么理由这样做吗?

It seems completely pointless to me. Do you have any reason for doing it?


我看到

很多人这样做,但没有测试结果,如:


if(tmp ==(char *)NULL)

..关于malloc()的一些代码失败......


施法有什么意义吗?
I see
many people do that, but not test the result such as :

if (tmp == (char *) NULL)
.. some code about malloc() failing ...

Is there any point in casting it?



不是我能想到的。另一方面,测试返回值是至关重要的。


我建议你找一个提倡演员的人,并问他们为什么。大多数可能是b $ b,他们不知道。如果你发现某人确实知道他们为什么要投票,为什么不向他们展示他或她b $ b给你的原因,并问我们我们怎么想呢?


-

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

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

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

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

Not that I can think of. Testing the return value, on the other hand, is
crucial.

I suggest you find someone who advocates the cast, and ask them why. Most
likely, they won''t know. In the event that you find someone who does know
why they''re casting, why not present this group with the reason he or she
gives you, and ask us what we think of it?

--
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


这篇关于转换malloc()的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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