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



Hi Dave,

I'm a bit lost. What problem did this cause for you, exactly?

Passing a parameter that's too long won't hurt anything. Granted, the routine you've called won't be able to access anything past it's declared length -- but other than that, it shouldn't cause a problem.

Prototypes are intended to protect against the opposite problem: Passing data that's too short. Such as when a caller has a 45A and calls a procedure/pgm where the parm is declared as 100A. This is downright dangerous, because the called routine will potentially read/write memory that doesn't belong to the caller's variable (because it's accessing data past the allocated spot in memory.) If you use CONST, RPG "fixes" the problem by declaring a larger space, and copying the 45A to 100A, so there's no danger (and therefore no reason to signal an error.)

But, the problem you describe, where the caller's variable is too long doesn't pose any risk of memory corruption. It can't access the whole variable, but the part that it does access is still within the bounds of the caller's variable, and therefore safe to use.

So I'm surprised by how you say this "bit you" and that you wish the system would warn you? What problem does it cause?




On 3/23/2012 6:22 AM, Dave wrote:
Hi, all,
I think this subject has been well debated in the past, but I just got
bitten again and would like to know how to protect myself in the
future. I copied and adapted some code and did not realise until well
into testing that I was passing a 100A parameter to a procedure
expecting 45A. I believe that when CONST is specified, the compiler
converts the parameter and there is no warning. I'm still wondering
why as I think that prototyping was introduced in order to protect one
against this sort of error. Now I discover that many other procedures
are doing the same call and I have to analyze to see if I can just go
ahead and change the 45A parameter to 100A


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.