|
Jim Wiant wrote: > > I'm looking for a way that I can display or print the value of a Pointer > in RPG IV. > > It's not important if it displays in Hex or Decimal, just so I can see > it's value. I can't find a way to either translate a Pointer into a > character or numeric dataname that's displayable. > You can call the C sprintf function with %p as the format type. It gives more information(*) than just the 16 byte value; more important, it can tell the difference between data that looks like a pointer and data that _is_ a pointer. You can have 16 bytes with the exact same value as a pointer, but it might not be a real pointer as far as the system is concerned (real pointers have a "pointer bit" set somewhere in the system that tell the system that your particular 16 bytes of storage contains a valid pointer). H bnddir('QC2LE') D fmtPointer pr extproc('sprintf') D buf 65535a options(*varsize) D template * value options(*string) D pointer * value D pointerVal s 100a D p s * inz(%addr(fld1)) D fld1 s 10a /free callp fmtPointer(pointerVal : '%p' : p); // get rid of the null-terminator that sprintf added pointerVal = %str(%addr(pointerVal) : %size(pointerVal)); // pointerVal = 'SPP:0000 :1aefQPADEV0008BMORRIS 648142 :1b5c0:0:2503' *inlr = '1'; (*) I don't know what all that information about the pointer actually means; maybe the sprintf documentation says. Here's a version of the program that tests a pointer that has a value that _looks_ ok, but isn't. H bnddir('QC2LE') D fmtPointer pr extproc('sprintf') D buf 65535a options(*varsize) D template * value options(*string) D pointer * value D ptrds ds D p * inz(%addr(fld1)) D pchars 1a dim(16) overlay(p) D temp s 1a dim(16) D pointerVal s 100a D fld1 s 10a /free callp fmtPointer(pointerVal : '%p' : p); pointerVal = %str(%addr(pointerVal)); // pointerVal = 'SPP:0000 :1aefQPADEV0008BMORRIS 648142 :1b5c0:0:2503' // 1. Copy the 16 bytes of the pointer to a character array // 2. Copy the data back to the original storage. The 16 // bytes of "ptrds" would look identical, but the pointer p // won't be valid any more. temp = pchars; // 1 pchars = temp; // 2 // Try EVAL ptrds:x in the debugger before and after // the pchars = temp callp fmtPointer(pointerVal : '%p' : p); pointerVal = %str(%addr(pointerVal)); // pointerVal = 'NULL' *inlr = '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.