Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Library functions

Name: Anonymous 2007-11-05 15:34

If we are writing a library with a function that should ultimately return a string of varying size, could be anything from several thousand KB or a few bytes.

Do you prefer if the function returns the string or manipulates a pointer argument to return the string? Or perhaps both?

If it were to return the string then of course it would have to return NULL on failure and perhaps set some global error variable, maybe errno.

But if it were to simply manipulate a pointer argument and put the string in there then it could return integer error codes.

I'm asking what you as C programmers prefer because this is my first real open source project and it will be a programming library put up for public use.

Personally, i think i'd prefer if the function only returned the pointer because in this case it must also take a struct argument.

This is the kind of pointless question i would only dare ask on an anonymous board for fear of humiliation among my cybernets peers.

Name: Anonymous 2007-11-05 20:08

Also NULL is pretty much the standard 'error' for any C function that allocates memory.
No it's not, implementations of malloc might return NULL or a unique pointer if an error occurs, else a valid pointer.
same for realloc and calloc.
You may ask "what the fuck?!"
yep.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List