Re: Resulting string from concatenation operator?



Thomas David Rivers wrote:
So,

I've been trying to determine something...

When concatenating two strings; there are
several sets of rules to apply - but basically
the operands of the concatenation operator
must be converted to the same type.

The PL/I standard refers to <string-type> which
is either BIT or CHARACTER, indicating (loosely)
that the operands must be either BIT or CHARACTER
strings, and if not, the offending operand is converted.

Contemporary PL/I compilers also have the GRAPHIC string to support DBCS data.

The IBM compiler has the same idea, with a different
hierarchy for how this conversion is to proceed.

The IBM documentation and the PL/I standard both
indicate that once the operands are converted
to the same type, the result of the concatenation
is that type.

However, I can't find anything that speaks
to the "other" attributes, in particular VARYING,
VARYINGZ and FIXED.

FIXED is a coded arithmetic attribute, not a string attribute; if a string variable or parameter does not have the VAR or VARZ attribute then it is fixed length.

The VAR and VARZ attributes or lack of them apply to variables and parameters. If the intermediate result of expression evaluation is a string it can be assigned to or passed to a variable or parameter of either fixed or varying length.


That is, the result of concatenating two CHARACTER FIXED
strings is clearly a CHARACTER FIXED.

Regardless of the varying or non varying nature of the strings concatenated, the result of concatenating two more X strings, where X is either BIT, CHARACTER, or GRAPHIC is an X string whose length is the sum of the current lengths of the strings concatenated.

But, what is the result of concatenating a CHARACTER FIXED
and a CHARACTER VARYING? And, what if the result
of the concatenation were assigned to a CHARACTER FIXED/
CHARACTER VARYING; a poor choice would lead to
yet another conversion. What if the operation would
succeed if one choice is made (say - a choice to the larger
string) but loose characters if the other is made?
But, then, choosing the type of the larger string might
lead to unnecessary runtime storage...

It seems to me that there would be benefit in being
able to concatenate disparate CHARACTER strings
(with respect to the VARYING/FIXED/VARYINGZ attribute).
But, if you have:

DECLARE V1 CHARACTER(200) VARYING;
DECLARE F1 CHARACTER(200);
DECLARE DV1 CHARACTER(30) VARYING;
DECLARE DF1 CHARACTER(30);

DV1 = V1 || F1;

DF2 = V1 || F1;

In both cases, the intermediate result is a string of length l+200 where l is the current length of V1. The compiler always allocates enough temporary storage to handle the worst case. Since l+200>=30, The first 30 characters are assigned to the result variable; in the case of DV1, the current length is set to 30.


Just what happens? Is it defined in the standard,
or simply left unspoken? Is either V1 and/or F1
converted to a temporary of the VARYING/FIXED
type and then the concatenation produces a temporary
of some type (VARYING or FIXED) which would
then be assigned to the target (after another potential
conversion?) Does the ultimate destination of the value
play into the conversion rules at all?

Is there some definitive reference for this?
- Thanks -
- Dave Rivers -


.



Relevant Pages

  • Re: Resulting string from concatenation operator?
    ... that the operands must be either BIT or CHARACTER ... strings, and if not, the offending operand is converted. ... the result of the concatenation ... to the "other" attributes, in particular VARYING, ...
    (comp.lang.pl1)
  • Resulting string from concatenation operator?
    ... that the operands must be either BIT or CHARACTER ... strings, and if not, the offending operand is converted. ... the result of the concatenation ... to the "other" attributes, in particular VARYING, ...
    (comp.lang.pl1)
  • Re: [Lit.] Buffer overruns
    ... fixed-length strings padded with blanks. ... PL/I always had both fixed and counted varying, ... It is possible in some languages and sometimes useful to ... 'mark' bit for every character cell of storage. ...
    (sci.crypt)
  • Re: Resulting string from concatenation operator?
    ... nonvarying temporary and a descriptor to identify the actual length. ... If the temporary were nonvarying or varying, ... what temporary would you create for a CHARACTER(*) VARYING ... Since the compiler always knows the length of a VARYING operand when the concatenation is performed the temporary is always exactly long enough to hold the result. ...
    (comp.lang.pl1)
  • Re: Why are Variable-Length Character Strings Taking so Long to ?Implement?
    ... Richard Maine observed that PL/I had varying ... Where is the description of F2003 varying length character strings? ...
    (comp.lang.fortran)