Hi Rory,
Like you, I don't know 100% for sure. What I say here is an educated
guess, based mainly on experience:
If I call a program passing too many parameters, what will happen?
Caller allocates memory for an integer to contain the parameter count,
and a variable length array of pointers, one for each parameter.
(allocated memory would be %size(pointer) * parameter count.)
Called program will behave differently, depending on the language.
assuming the called program won't throw a fit, but will OS/400 take note?
I don't think so, no. But, it may depend on how you called the
program. Did you use the CALL command? a *CMD interface? The SQL Call
command? But, AFIAK, the OS doesn't really care. Other than having a
different value for the parm count, and allocating a little more memory
for the pointer array.
know some IBM programs throw an error, but I assume (again!) that this is
program-specific code which checks for too many parameters.
In the *called* program, yes. But not in the caller or OS.
For example, an OPM CL program *must* be passed the exact number of
parameters that it's expecting. Otherwise, it'll throw an error.
OPM RPG will throw an error if you pass too many parameters, but NOT if
you pass too few.
ILE RPG won't throw any error, but the user-written code is able to
check the parameter count via the %PARMS BIF or PSDS. So while RPG
itself won't care, the user written code might care, or might malfunction.
ILE CL works like ILE RPG, it doesn't care if you pass the right number
of parameters. (Except, I don't know how to get the parameter count in
ILE CL -- but there might be a way, maybe it's just me.)
ILE C works like ILE RPG as well, except that unlike ILE RPG, the extra
parameters would be accessible to the program, since the program doesn't
necessarily need to know the number of parameters at compile-time.
If I define a prototype for the called program with the extra parameter
being CONST, could there be any memory overwriting problems? I don't think
so, but I'd like to know.
No, there shouldn't be, since the caller knows the right number of
parameters and is the one that allocates the memory.
But, again, some languages will check the parm count and complain if it
doesn't match, so your idea might not work, depending on whether you
need to call those languages.
As an Amazon Associate we earn from qualifying purchases.