|
The following can be used to retrieve a non-const ptr to a const parameter.
Use at your own risk--no warranty is expressed or implied and none is given.
Create a C module using PDM option 15 or CRTCMOD (no special parameter needed)
from the following source member:
// Mbr: GETCONST
#include <stdio.h>
void* GetConstPtr(const char* pConst);
void* GetConstPtr(const char* pConst)
{
return (void*)pConst;
}
Create the test case RPG IV source member using PDM option 15.
Then do:
CRTPGM TESTCONST MODULE(TESTCONST GETCONST)
Start debug and set a break point at the call to myProc(qData:%len(qData)).
Step to the next line and look at the field named GDATA. The subprocedure which
accepts it as a constant value, actually changes the value of the GDATA variable
using a non-const ptr.
// Mbr: TESTCONST
H BNDDIR('QC2LE')
D GetConstPtr PR * ExtProc('GetConstPtr')
D szConstData 64A Const
D gData S 20A Inz('Cozzi Sucks!')
D myProc PR
D someData 64A Const OPTIONS(*VARSIZE)
D ndataLen 10I 0 Const
/free
myProc(gData:%len(gdata));
*INLR = *ON;
/end-free
P myProc B
D myProc PI
D someData 64A Const OPTIONS(*VARSIZE)
D ndataLen 10I 0 Const
D pLocalPtr S *
D localData S 64A Based(pLocalPtr)
/free
pLocalPtr = GetConstPtr(someData);
if (pLocalPtr <> *NULL);
%subst(localData:1:nDataLen) = 'No he doesn''t!';
endif;
return;
/end-free
P myProc E
-Bob Cozzi
www.iSeriesTV.com
Ask your Manager to watch iSeriesTV.com
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Bob Cozzi
Sent: Thursday, August 31, 2006 4:20 PM
To: 'RPG programming on the AS400 / iSeries'
Subject: RE: Allocate field with options(*nopass :*omit)
That's what I remember, but I thought it didn't work in V5.1?
The other thing I think "works" now and didn't previously was this (in C):
void* GetConstPtr(const void* pConst)
{
return pConst;
}
-Bob Cozzi
www.iSeriesTV.com
Ask your Manager to watch iSeriesTV.com
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Barbara Morris
Sent: Thursday, August 31, 2006 3:57 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Allocate field with options(*nopass :*omit)
Bob Cozzi wrote:
It depends on what release you're targeting the compile. If you're on V5.2 or later, I believe it works. It should/does work on V5.3. It was supposed to work on V3.7 but nobody complained until long after V5.1
was
out.
You can't assign the value of %addr(constparm) on any release. The change made in v5r1 was to allow %addr(constparm) to be used in a comparison. (Not sure what you're remembering about v3.7 and "long after v5.1".)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.