pointer as second argument instead of returning pointer?

Posted by Tyler on Stack Overflow See other posts from Stack Overflow or by Tyler
Published on 2010-03-26T02:13:44Z Indexed on 2010/03/26 2:23 UTC
Read the original article Hit count: 486

Filed under:
|
|
|

I noticed that it is a common idiom in C to accept an un-malloced pointer as a second argument instead of returning a pointer. Example:

/*function prototype*/    
void create_node(node_t* new_node, void* _val, int _type);

/* implementation */
node_t* n;
create_node(n, &someint, INT)

Instead of

/* function prototype */
node_t* create_node(void* _val, int _type)

/* implementation */
node_t* n = create_node(&someint, INT)

What are the advantages and/or disadvantages of both approaches?

Thanks!

© Stack Overflow or respective owner

Related posts about c

    Related posts about best