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




What I don't understand is how, inside the procedure, to make RPG
understand that the pointer is a string pointer so that I can do %subst
and all the other usual string operations on the argument.

Pass an actual STRING to the procedure. Pass it by reference (rather than by VALUE) so that all that gets passed under the covers is the address of the variable. Then you don't need to work with pointers at all, and you'll be able to use string operations on it.

If you want any size variable to be used as input, add options(*varsize) to the prototype, and it'll allow any size variable to be passed. However, if you do that, be very careful not to refer to the memory beyond what the caller passed in, or you'll be looking at memory that doesn't belong to you.

RPG does not have data types for pointers, as C does. I think you're probably coming from a C background, because it (and C++) are the only languages I know of that have the peculiar notion that a pointer should have a data type. A pointer is exactly that -- a pointer. It's a variable that holds an address.

IMHO, what scares people away from working with pointers is the complexity of using them in C where they're not just pointers, but also specify a view of memory... then you get into things like casting pointers to other pointers, or dereferencing a pointer that the pointer points to... it gets very complicated very quickly in C... and people get scared.

Pointers in RPG are much simpler. They're just variables holding an address. That's it. If you want to view what's at that location in memory, you declare a variable that's based on that pointer -- then that variable uses the memory that the pointer points to. Very simple.

But all of this is unnecessary for what you want to do -- all you need to do is pass the character field by reference. You don't need pointers or based variables.

Unless, of course, you're trying to implement your own "string class" that allows more than 64k of data in a character variable. If you're doing that, then you'll have to use BASED and pointers -- but I'd recommend NOT using RPG's string opcodes in that case. I'd also recommend adding a level of abstraction so that the caller doesn't know that he has to pass a pointer, instead of that have some sort of "String Data Type" that gets passed.

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.