|
The error code is made available by the GetErrNo() function, which is a remapped __error() C function. The GetErrNo() function gets access to the ErrNo variable through a pointer. The ErrNo variable contains the error code. Before issuing any function that returns an error code, the ErrNo variable should becleared. However, it is possible only after the GetErrNo() function was performed. If the error code is not cleared before the function is entered, the resulting error
code may be false.errno - as I know you know - is a global variable used by everything - it is not changed if not error occurs, so setting it to 0 just before a function that might set it and then checking it after is how I understand doing this.
Not all functions return an error code - an example is StrToD - it returns a float value - it is commonly used to test whether a string is numeric - the only reliable test for errors is to set errno - the global variable - before calling StrToD and then checking it after the call.
Tightly coupling the setting and checking will not cause problems with other functions, as far as I know.
Regards Vern At 08:40 PM 11/19/2006, you wrote:
I consider setting errno to zero to be a bad practice. You risk screwing up other routines when you set it to zero. You also risk getting "false alarms" when you use it to determine if something failed. It's not rocket science. Each API returns a value to tell if you if it succeeded or failed -- use THAT VALUE to determine if it failed. Use errno to get a description of the last error (from any routine) that failed. Why do people insist on doing this another way?! -- Scott Klement http://www.scottklement.com On Fri, 17 Nov 2006, Vernon Hamberg wrote: > Scott > > As you say, functions that set errno do not change it if they end > successfully. That is why it is good practice in C to set it to 0 > before any call to such a function. I have been able to set errno in > RPG - just need to call the geterrno() function (I think) to retrieve > it the first time, so that the pointer is set to the location of > errno. After that, the variable based on the pointer to errno can be > set to 0. Least it has worked for me - i've tried to learn my lessons > about pointers from you!! > -- This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.