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



Simon Coulter wrote:
... So although C always widens the return value telling RPG that it's
not widened makes things work. Why is that so? Is it because RPG is
being warned that a C function is being called, it knows the C
function will always widen the return value, and so it adjusts which
bytes of the return value it uses according to the size and type of
the variable specified on the left-hand side of the assignment? My conclusion is that unless I specify either *CWIDEN or *CNOWIDEN I cannot make C and RPG behave properly and since I have other reasons for not using those my only option is to write a conversion routine in a language other than C (e.g., RPG) to convert the int returned by C into a 1-byte char for use by RPG or COBOL.

Can anyone (hello Barbara) confirm this?

Scott explained how *CNOWIDEN controls more than just widening. It also controls whether the 1-byte return value is treated as an aggregate (character string) or as a scalar (integer).

You are correct that when a C function returns char and the RPG prototype is defined without any special EXTPROC value, then the RPG prototype would have to define the return value as a 1-byte unsigned integer, and then the caller would have to convert the returned value to a 1-byte char.

By the way, you can write a C function to return a 1-byte aggregate by defining the return value as a struct with a 1-byte subfield.

Also by the way, starting in V6R1, this difference regarding single-byte return values disappears. Aggregate return values up to 16 bytes get handled by the system in the same way as scalar return values.

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.