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:29

>>10

I'm fairly certain ANSI C requires NULL to be returned on a malloc error.  I've not personally seen an implementation that does otherwise, but I don't doubt they exist ;)

I do realize errno is available, and required to be set on failure for the the Unix98 standard, but in practice(At least what I've worked on) this is rarely used.  Also I don't think this behavior is defined by ANSI.

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