This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Returning status from C functions


> Date: Wed, 26 Jul 2000 15:18:30 +0100
> From: Ian Grant <Ian.Grant@cl.cam.ac.uk>
> 
> I have a library function, func - say, that returns status as an integer.  In 
> the header file, as usual, there is a set of #defines allowing me to  write
> 
>      if (func() != FUNC_OK) .. etc
> 
> When I wrap this for guile, I could either return symbols FUNC_OK, 
> FUNC_FAILED_THIS_WAY, FUNC_FAILED_ANOTHER_WAY etc, or I could scm_sysintern 
> integers like
> 
>     scm_sysintern("FUNC_OK", SCM_MAKINUM(FUNC_OK));
> 
> and have my wrapper return scheme integers.
> 
> Which is better?  Thi points out that symbols can be used in a case statement 
> and the integer definition of FUNC_OK can't.  On the other hand I can see uses 
> for the integer value.  Of course it's easy to convert from one to the other 
> too - but which should be the default?

Returning an integer has the advantage that if you run into a value
which isn't supported by the predefined symbols in the C wrapper, you
can still compare the values without needing to modify the wrapper and
recompile.

I think this useful at least for the system call wrappers in libguile,
since there's no definitive set of possible values that need to be
supported, but isn't a consideration if the original C function is
part of your own project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]