On Mon, 21 Apr 2008 13:19:37 -0500 (CDT) in comp.lang.c.moderated, Al
<two@[EMAIL PROTECTED]
> wrote:
>Hi there,
>
>I haven't kept up with the latest C best practices. In adapting
>(wrapping, mostly) a C++ API which throws on error, which of these might
>the better alternative, or are there other options I haven't considered?
>
>/* Assume: */
>
>typedef struct { ... } Error;
>struct Foo;
>
>/* Parametric (stateless) version: */
>Foo* CreateFoo (int ctorparam, Error *const error);
>bool PrintFoo (const Foo *const foo, Error *const error);
>bool ReleaseFoo(const Foo *const foo, Error *const error);
>
>/* Static (stateful) version: */
>Foo* CreateFoo (int ctorparam);
>bool PrintFoo (const Foo *const foo);
>bool ReleaseFoo(const Foo *const foo);
>Error* LastError ();
What do formatted output functions return and what value indicates
failure?
What does fclose() return and what value indicates failure?
What error indicator is set by I/O function failures?
>In both versions, the functions return NULL or false on error. In
>addition, the parametric version sets its second parameter appropriately
>in case of error. The static version instead sets a global, much like
>errno, which can be retrieved using LastError.
>
>Of course, this global is not truly so; it uses thread-local storage to
>achieve lock-free thread-safety. The first one is 'cleaner' in one
>sense, but also more verbose. The second is simpler, but has the problem
>that TLS, though fairly ****table, is not part of the language.
>
>A related question is whether there's a consensus on returning true or
>false (or non-zero : zero) on error. I've seen different libraries use
>both, which is unfortunate.
What do filesystem operation functions return and what value indicates
failure?
>Any guidance appreciated!
Check out any decent C library reference section on stdio functions and
use that as your guide.
Also note from Commandment # 6: "thy creativity is better used in
solving problems than in creating beautiful new impediments to
understanding."
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@[EMAIL PROTECTED]
(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
--
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
-- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line. Sorry.


|