【发布时间】:2010-03-26 02:13:44
【问题描述】:
我注意到在 C 中接受 un-malloced 指针作为第二个参数而不是返回指针是一种常见的习惯用法。示例:
/*function prototype*/
void create_node(node_t* new_node, void* _val, int _type);
/* implementation */
node_t* n;
create_node(n, &someint, INT)
代替
/* function prototype */
node_t* create_node(void* _val, int _type)
/* implementation */
node_t* n = create_node(&someint, INT)
这两种方法的优点和/或缺点是什么?
谢谢!
编辑谢谢大家的回答。选择 1 的动机现在对我来说非常清楚(我应该指出,选择 1 的指针参数应该 malloc'd 与我最初的想法相反)。
【问题讨论】: