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



Steve Richter wrote:
I have C and C++ code that parses command strings and does some specialized
scanning that I would like to port from visual C++ to ILE. These functions
accept pointers as arguments, some that are pointers to const data.  In some
cases prototyping as %string works, but other times simply passing a pointer
is best.

In general I would like to find out if mix and matching C++ and RPG
procedures works better than coding entirely in RPG. But the RPG limitation
of setting a pointer to only non const variables will not work well with C++
which makes heavy use of const references and pointers.

Basically, if RPG provides the pointer, why restrict it to only non const
variables?  Esp since const is such a good modular programming practice and
the solution of qualifying a pointer and DS as const appears to be very
doable.
If I'm not mistaken, C and C++ also have (annoying) restrictions on
what you can do with const pointers.

In RPG, if you were able to save the address of a CONST parameter,
you could effectively do anything you wanted to the data pointed at
by that pointer. You might muck up data in the passed parameter, or
you might muck up data on the call stack, or you might even change
data in the constant data section of store.

I suppose we could extend the language to allow you to define
pointers as "CONST" in RPG. That would then require some way of
restricting their use. Perhaps variables BASED on a CONST pointer
would have to be considered read-only. (I'll add this to our list of
proposed enhancements.)

In general, there are plenty of good alternatives in RPG to using
pointers (which I sometimes regret adding to the RPG IV language).
As Barbara and I have pointed out, if you're passing a pointer from
C to RPG, you can define the parameter in RPG as either a reference
or a const parameter. Just because you're dealing with pointers in
C/C++ doesn't mean you have to program that way in RPG.

BTW, are you familiar with Barbara's document describing how to call
between C and RPG:  <http://www.opensource400.org/callc.html>

Cheers!  Hans





As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.