× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




The error reporting machinery centered about the setting of errno is
generally regarded with tolerance at best.  It requires a
``pathological coupling'' between library functions and makes use of
a static writable memory cell, which interferes with the construction
of shareable libraries.

Amen to that!

I hate it when people use global variables and IMPORT/EXPORT variables. They interfere with the modular process. and that's really all "errno" is... it's a global variable exported from a service program (when they say "library" they mean service program, for those who may not be familiar with Unix terminology)


"3 The value of errno is zero at program startup, but is never set to
zero by any library function.170) The value of errno may be set to
nonzero by a library function call whether or not there is an error,
provided the use of errno is not documented in the description of the
function in this International Standard."

This is what I was talking about in my previous message. C programs expect errno to remain the same. You have to make adjustments for the environment, though. It says "program starttup" above, but on the System i, it's actually "activation group startup".

And when it says "never set to zero by any library function" it means that it's never set to zero by any API that you call. You should follow this standard too! Don't change it! Your programs may end up being used as APIs someday.

"170) Thus, a program that uses errno for error checking should set
it to zero before a library function call, then inspect it before a
subsequent library function call. Of course, a library function can
save the value of errno on entry and then set it to zero, as long as
the original value is restored if errno's value is still zero just
before the return."

In my opinion, if I haven't yet made it clear (and I think I have) is that you should always treat your code as if it's part of a library function. (To use the terminology used in the quoted paragraph.) IF it isn't one today, it might be one tomorrow. We should be writing modular, reusable code, and if we're doing that, we want to make sure we don't muck with the value of errno.

Remember, the C programming language is not new, it's more than 30 years old. Like RPG, a lot of the old programs were written in a monolithic fashion. The standard you're quoting is from 1989! Today, we should be writing modular code.

Vern, even if you're not new to using errno, I suspect that a lot of the people reading this message are -- I just don't want them to learn bad habits!

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.