|
On 13/01/2006, at 11:33 AM, Barbara Morris wrote:
Simon Coulter wrote:Problem 2 is that C expects an int (4 bytes) but the prototype is passing a 2-byte integer. RPG will widen the value because that's what C expects but you shouldn't rely on this behaviour.Actually, RPG doesn't widen the value. Sometimes the parameter can getpassed in a register, and that makes it appear as though RPG widened thevalue, but if the system doesn't have a register available, theparameter gets passed "on the stack" (I don't know the mechanism). Whenthat happens, the called function doesn't get the value that the caller passed.
I'd always understood RPG didn't widen and I fully expected the original example to fail due to the RPG prototype specifying a 2-byte integer but I tried it in debug to confirm and the C function received a 4-byte integer if I passed either a literal, a 5I0, or a 10I0 so I presumed RPG was widening it.
Hmm, what would happen if the C function expected a short and the value was passed in a register? I presume I don't have to worry about this and it will be "taken care of" by the run time.
Regards, Simon Coulter. -------------------------------------------------------------------- FlyByNight Software AS/400 Technical Specialists http://www.flybynight.com.au/ Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 /"\ Fax: +61 3 9419 0175 \ / X ASCII Ribbon campaign against HTML E-Mail / \ --------------------------------------------------------------------
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.