Mail Archives: djgpp-workers/2003/11/08/07:09:17
Hello.
Kbwms AT aol DOT com wrote:
>
> Attached to this email is the C code that implements global variable
> math_errhandling and associated macros.
Cool, thanks!
> Noted below are additions to math.h:
>
> #define MATH_ERRNO 1
> #define MATH_ERREXCEPT 2
> extern int math_errhandling;
>
> int get_math_errhandling (void);
> int set_math_errhandling (int);
> void set_errno (int);
> int raise_except (int);
This are functions internal to libc. They should be prefixed with "__", to
avoid polluting the global namespace. They should also go in the not-ANSI,
not-POSIX section of <math.h>.
I'd also suggest that set_errno and raise_except are renamed. These names are
fairly generic and not obviously related to the maths module. How about these
names instead?
__get_math_errhandling
__set_math_errhandling
__math_set_errno
__math_raise_exception
The second two have math at the start of their names, because they're internal
to the maths module. The first two actually manipulate math_errhandling, hence
they have get/set at the start of their names.
[snip]
> Comments are welcome. Please look the code over and let me know whether
> there is a gotcha lurking.
Do the maths functions use get_math_errhandling, to get the value of
math_errhandling? Or do they just read math_errhandling? If they look at
math_errhandling, then get_math_errhandling is useless. The library user could
modify math_errhandling, making the value returned by get_math_errhandling
completely bogus.
It would be better for math_errhandling to be a macro calling
get_math_errhandling. That way the user cannot modify math_errhandling. Put
something like this in <math.h>:
#define math_errhandling (__get_math_errhandling())
And modify errhndlr.c like this:
[snip]
> int math_errhandling;
[snip]
static int math_errhandling = 0;
Then use math_errhandling instead of LocalMathErrHandling in the code.
What do you think?
Thanks, bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
"You can't evaluate a man by logic alone." -- McCoy, "I, Mudd", Star Trek
- Raw text -