× 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.



Scott,

I think my confusion is drawn from the way the API documentation reads. As
an example, I'll compare the returned variables from calls to iconv_open()
and iconv():

iconv_open(): This has a return variable of datatype iconv_t. This is a
structure composing an int (the return value) and an int array (12 elements
containing fromccsid, toccsid, shift state, etc...).

For the return value the documentation states: If successful, iconv_open()
returns a conversion descriptor of data type iconv_t. This conversion
descriptor must be passed unchanged as an input parameter to the iconv() and
iconv_close() functions. If unsuccessful, iconv_open() returns -1 in the
return value of the conversion descriptor and sets errno to indicate the
error.


iconv(): This has a return variable of datatype size_t. This is an unsigned
int (the return value).

The documentation states: If the entire input buffer is successfully
converted, iconv() may return the number of nonidentical conversions
performed based on the substitution alternative. See iconv_open()--Code
Conversion Allocation API
<http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/iconvopn.htm>
and QtqIconvOpen()--Code Conversion Allocation API
<http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/QTQICONV.htm> .
Otherwise, zero will be returned. If an error occurs, iconv() returns
(size_t)-1, and errno is set to indicate the error.


To me, this suggests that iconv_open() will return the value -1 in the
return value if an error occurs. This is consistent with an int. However,
iconv() will return the value (size_t)-1 if an error occurs. As size_t is an
unsigned int it must initially be positive, so unless size_t is initially
set to zero the return value can't be negative. This is consistent with an
unsigned int.

This is my dilemma: Wouldn't the documentation simply state that iconv()
returns -1 on error, rather than (size_t)-1 if the return value could be
negative? It seems too deliberate to decrement size_t by 1 rather than set
it to a negative value.

Larry

On 8th March Scott wrote:

In most cases, it's just easier for the RPG programmer to use 10I 0 so
they can compare it with -1 (since RPG doesn't have casting, you can't
cast -1 to size_t like you can in C)



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.