PL/I

PL/I

PL/I

 View Only
Expand all | Collapse all

DEFINED attribute and ADDR builtin

  • 1.  DEFINED attribute and ADDR builtin

    Posted Mon October 22, 2018 03:53 PM

     

    In the following example:

     SMALL:   PROCEDURE OPTIONS (MAIN);

     

      /* The variable NAMES is a defined variable; its data */

      /* description is mapped to the storage occupied by */

      /* the variable LIST. Any reference to NAMES or to */

      /* LIST is resolved to the same location in memory.  */

     DECLARE NAMES(10) CHARACTER(5) DEFINED (LIST), 

            LIST(10) CHARACTER(5); 

     

     DCL P1 POINTER, P2 POINTER;

     

     NAMES(1) = 'NAME1';

     

     DISPLAY('NAMES(1) is "' || NAMES(1) || '"');

     DISPLAY('LIST(1) is "' || LIST(1) || '"');

     

     P1 = ADDR(NAMES);

     P2 = ADDR(LIST);

     

     DISPLAY('P1 is ' || HEX(P1));

     DISPLAY('P2 is ' || HEX(P2));

     

     END;

     

    The compiler declares this error:

     

    defined.pli(19:2) : IBM1246I E Argument to ADDR built-in should be CONNECTED.

     

    For the ADDR(NAMES) line.

     

    Why would NAMES not be considered CONNECTED?   And furthermore, you can't decorate NAMES

    with the CONNECTED attribute (as CONNECTED only applies to parameters and descriptors.)

     

    Is there no way to determine the ADDRess of a DEFINED variable?

     

    tdr


  • 2.  Re: DEFINED attribute and ADDR builtin

    Posted Mon October 22, 2018 06:36 PM

    The manual notes that:

    An array overlay-defined on another array is always assumed to be in unconnected storage.

    although overlay-defined doesn't seem to be a proper descriptive term, as earlier the manual states that "there are three types of defining: simple, iSUB, and string overlay."

    I expect there's a bit of a disconnect here, with the compiler internally marking NAMES() NONCONNECTED by the above assumption, and later semantic checks for ADDR() issuing the diagnostic that's not as direct as one might wish.

    In cases like this where we know that in fact the arrays correspond exactly, BASED(ADDR(base-variable)) can be used instead of DEFINED(base-variable).

    Bernie

    brataj