是否有其返回的结构直接是很好的做法无论如何? [英] Is there any case for which returning a structure directly is good practice?

查看:97
本文介绍了是否有其返回的结构直接是很好的做法无论如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IMO所有code直接返回结构可以被修改以返回指针结构

IMO all code that returns structure directly can be modified to return pointer to structure.

当直接返回一个结构好的做法呢?

When is returning a structure directly a good practice?

推荐答案

修改的怎么样?返回指针的结构的静态实例的功能内,从而使功能非折返;或者通过指针返回给调用者必须确保自由,这样做appropiately堆中分配的结构?我会考虑返回的结构是在一般情况下,很好的做法。

Modified how? Returning a pointer to a static instance of the structure within the function, thus making the function non-reentrant; or by returning a pointer to a heap allocated structure that the caller has to make sure to free and do so appropiately? I would consider returning a structure being the good practice in the general case.

这篇关于是否有其返回的结构直接是很好的做法无论如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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