I'm writing some functions that manipulate strings in C and return extracts from the string.
What are your thoughts on good styles for returning values from the functions.
Referring to Steve McConnel's Code CompleteSteve McConnell's Code Complete (section 5.8 in 1993 edition) he suggests I use the following format:
void my_function ( char *p_in_string, char *p_out_string, int *status ) The alternatives I'm considering are:
Return the result of the function (option 2) using:
char* my_function ( char *p_in_string, int *status ) Return the status of the function (option 3) using:
int my_function ( char *p_in_string, char *p_out_string ) In option 2 above I would be returning the address of a local variable from my_function but my calling function would be using the value immediately so I consider this to be OK and assume the memory location has not been reused (correct me on this if I'm wrong).
Is this down to personal style and preference or should I be considering other issues ?