[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IDL issue

From: Espen Skoglund
Subject: Re: IDL issue
Date: Mon, 9 Jul 2007 14:28:28 +0200

[Jonathan S Shapiro]
> The question is: should the C stub return the error code or the
> return value?

> Concrete example:

>   idl:   float f(int arg);
>   C:     float f(int arg, IDL_Env *_env);  [return result value]
>   C:     result_T f(int arg, float *_retVal, IDL_Env *_env);
>          [returns error code]

> When the result value is returned, the error code is generally
> stored into a dedicated slot within the IDL_Env structure.

> In my opinion, returning the error code is better for two reasons:

>   1. It leads to more consistent error checking:
>   2. It avoids an initialization problem.

> Reactions/opinions?

I agree with you.  Returning the error code is more consistent.  Also
it prevents programmers to write code like:

    if (f(arg, &idlEnv) == foo) {}

which does not take the error code into account.  They would have to
write something like, e.g., the following instead:

    if (f(arg, &retVal, &idlEnv) == OK && retVal == foo) {}

This might eliminate some problems due to sloppy programming.  The one
argument I can think of in favour of returning the result value is a
performance related one.  The architecture calling conventions
typically assign return values to registers depending on the return
type.  E.g., floating-point values are returned in different registers
than integer values, multi-word values can be returned in multiple
registers, etc.  By having the function always return the error code
you prevent the compiler to perform these optimizations.  Of course,
the performance overhead here is most likely negligible so the
argument is probably kind of moot.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]