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 17:26

>>6
I'm not sure what you mean with the variable strings statement.

Of course i will have to allocate memory, that's the whole point of the function to return a string that can be both small and big, how big is determined inside the function and i will allocate when i need it.

So you mean i should return NULL at errors, that's what i was going for so i think that's the best way really.

Thank you for your input.

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