Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Programming languages > RETURNS length
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 24th October 08:42
william m klein
External User
 
Posts: 1
Default RETURNS length



Robin (or anyone else),
According to:

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ibm3lr30/6.15

"String lengths and area sizes must be specified by constants. The returned
value has the specified length or size."

I *hate* to sound like "you-know-whom" - but can you help me (better) understand
your statement (in another thread)

" A PL/I function can return a character string whose current length depends on
an input string length or anything else."


--
Bill Klein
wmklein <at> ix.netcom.com
  Reply With Quote


  sponsored links


2 24th October 08:44
glen herrmannsfeldt
External User
 
Posts: 1
Default RETURNS length



I may not understand it all yet, but VARYING strings have a current and
a maximum length. The current length can change at anytime, the maximum
length needs to be at least known at allocation time.

-- glen
  Reply With Quote
3 24th October 08:44
william m klein
External User
 
Posts: 1
Default RETURNS length


Thanks. That makes sense and is the same way that COBOL (the language that I
know best) works.

Of course, someone (either the CALLing/INFOKing/whatever) program or the CALLed
subprogram (function/whatever) needs to get at least enough storage to hold the
"current" data, but as long as one or the other does, this does work (in the
systems that I know).

--
Bill Klein
wmklein <at> ix.netcom.com
  Reply With Quote
4 24th October 08:44
peter flass
External User
 
Posts: 1
Default RETURNS length


RETURNS( CHAR(whatever) VARYING ) will return a VARYING string with max
length "whatever" and current length determined by the data specified on
the RETURN statement, which sort of fits what the manual says, although
they could have been a little clearer. Multics PL/I used to allow
"RETURNS( CHAR(*) )" with or without varying, which is not allowed in
IBM compilers.
  Reply With Quote
5 24th October 08:45
tom linden
External User
 
Posts: 1
Default RETURNS length


As do our compilers both for Unix and VMS. Odd that IBM never implemented,
but it can be tricky, if the stack isn't cleaned on exit.
  Reply With Quote
6 24th October 08:45
glen herrmannsfeldt
External User
 
Posts: 1
Default RETURNS length


There are C library routines that return a string value, or, in
C terms, a pointer to a character array. Returning a pointer to
a static array avoids any allocation/deallocation problems, but
causes strange results if you call the routine more than once
before using the value.

PL/I has, in general, been much happier to allocate temporary
arrays than Fortran. It seems that some of the Fortran 77 CHARACTER
variable rules were designed to avoid allocating temporaries.

Otherwise, one can use CONTROLLED variables (like Fortran ALLOCATABLE),
allocate them in a called subroutine. It might be that they need to
be arguments and not a function return value, but it should work.
That way it can be allocated to the appropriate size, and deallocated
by the calling routine.

-- glen
  Reply With Quote
7 26th February 05:38
glen herrmannsfeldt
External User
 
Posts: 1
Default RETURNS "length"


I may not understand it all yet, but VARYING strings have a current and
a maximum length. The current length can change at anytime, the maximum
length needs to be at least known at allocation time.

-- glen
  Reply With Quote
8 26th February 05:38
william m. klein
External User
 
Posts: 1
Default RETURNS "length"


Thanks. That makes sense and is the same way that COBOL (the language that I
know best) works.

Of course, someone (either the CALLing/INFOKing/whatever) program or the CALLed
subprogram (function/whatever) needs to get at least enough storage to hold the
"current" data, but as long as one or the other does, this does work (in the
systems that I know).

--
Bill Klein
wmklein <at> ix.netcom.com
  Reply With Quote
9 26th February 05:38
peter flass
External User
 
Posts: 1
Default RETURNS "length"


RETURNS( CHAR(whatever) VARYING ) will return a VARYING string with max
length "whatever" and current length determined by the data specified on
the RETURN statement, which sort of fits what the manual says, although
they could have been a little clearer. Multics PL/I used to allow
"RETURNS( CHAR(*) )" with or without varying, which is not allowed in
IBM compilers.
  Reply With Quote
10 26th February 05:38
tom linden
External User
 
Posts: 1
Default RETURNS "length"


As do our compilers both for Unix and VMS. Odd that IBM never implemented,
but it can be tricky, if the stack isn't cleaned on exit.
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666