Skip to main content
Corrected author name and added link
Source Link
Matthew Murdoch
  • 31.6k
  • 32
  • 99
  • 127

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 ?

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

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

added 2 characters in body
Source Link
David
  • 14.1k
  • 25
  • 85
  • 102

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 Complete (section 5.8 in 1993 edition) he suggests I use the following format:

void my_function ( char *p_in_string, char*char p_out_string*p_out_string, int status*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*status ) 

Return the status of the function (option 3) using:

int my_function ( char *p_in_string, char*char p_out_string*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 ?

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

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

Source Link
David
  • 14.1k
  • 25
  • 85
  • 102

Function format in a C program

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