Hi Boris,
I assume you're familiar with the difference between passing data by 
reference (i.e. by pointer) and passing it by value, right?   That's 
pretty much standard fare for a C programmer.
When you pass a string as char*, you're passing it by reference -- that 
means, under the covers, all that's passed to the RPG program is a pointer.
In RPG, the program will receive a character string (which can be up to 
65535, by the way... though, in V6R1 it can be much, much larger). 
However, what the program is REALLY receiving (under the covers) is a 
pointer.  The 65535 character string is really just how the RPG program 
dereferences that pointer -- so it's viewing 64k of data starting at the 
address in the pointer.
Without changing any of your C code, that RPG program can choose to take 
the address of it's parameter, and (with a little pointer math) examine 
the memory beyond the 64k limit...
So, really, there's no need to change your C code.   It's the RPG side 
that needs to be modified.
Having said that... I would suggest (if you haven't done this already) 
that you pass an additional parameter that indicates the length of the 
character string, so the RPG program knows how much memory it's allowed 
to peruse.  Just pass an int containing the length, that should suffice.
Also, the RPG programmer doesn't necessarily have to deal with the issue 
via a pointer.  He/she could receive an array instead.  For example, if 
the parameter is received into the following RPG definition, it can be 
up to 16 MB long:
     D MyParm                       512A   dim(32767)
That's an array of 512 character strings.  Since there's 32k elements in 
the array, the total size is around 16MB.  The RPG programmer can then 
read through your data in 512 byte chunks...
I guess the tricky part is just making sure that the RPG programmer 
understands how to limit their use of the parameter to only the amount 
you've passed.  This is where the average RPG programmer will get 
tripped up, they'll try to access memory beyond the end of the data 
you've passed (RPG does not look for a \0 to indicate the end of a 
string like C does) and start accessing memory they have no business 
accessing.
Boris wrote:
Hi All
I need to pass several char* parameters to an RPG program. Each parameter 
can be quite long, up to 99999A, where the max parameter length that an RPG 
program can receive, to the best of my knowledge, is 32K and there is also a 
limitation of the total length of parameters. So I was thinking to pass the 
pointer to the RPG program. That's where I got stuck. My knowledge of RPG is 
very limited. Could someone please post a short sample program on how to 
pass a char* pointer to an RPG program and how to use it in the RPG 
program - let's say just display the value?
Thanks a lot in advance.
Boris. 
 
As an Amazon Associate we earn from qualifying purchases.