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-06 12:18

>>11
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.
errno is part of the POSIX standard. Just because it's not part of the standard library doesn't mean you shouldn't use it. Even on non-unix systems errno is easily ported (even with windows).

Also, errno is anything but rarely used (see >>12). Many fundamental libraries such as the BSD sockets library use errno; along with most standard library functions on POSIX-compliant systems.

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