Hi Frank,
It is not suppose to work. I mean it works exactly as expected, i.e.
SEGFAULT
"len" is declared in linkage section and not referenced in "using",
and that mean it is not allocated.
Referencing in "returning" does not allocate the memory for
variable.
Move it to working or local storage and everything will be fine.
Regards,
Sergey
On 6/28/2013 1:35 AM, Frank Swarbrick
wrote:
Anyone ever got this to work?
Take a look at this:
>>SOURCE FORMAT IS FREE
program-id. caller.
data division.
local-storage section.
77 str-len binary-long.
procedure division.
call 'callee1' using content 'This is a test'
returning str-len
display str-len
call 'callee2' using content 'This is a test!'
returning str-len
display str-len
goback.
end program caller.
program-id. callee1.
data division.
linkage section.
01 str pic x any length.
procedure division using str.
compute return-code = function length(str)
exit program.
end program callee1.
program-id. callee2.
data division.
linkage section.
01 str pic x any length.
01 len binary-long.
procedure division using str returning len.
compute len = function length(str)
exit program.
end program callee2.
callee1 works fine. callee2
causes a core dump or some such thing.
Looking at the generated C code I see the following:
/* PROGRAM-ID : callee1 */
static cob_u8_t b_8[4]; /* RETURN-CODE */
/* PROGRAM-ID : callee2 */
static cob_u8_t b_14[4]; /* RETURN-CODE */
/* PROGRAM-ID : callee1 */
static cob_field f_8 = {4, b_8, &a_3}; /*
RETURN-CODE */
static cob_field f_12 = {1, NULL, &a_1}; /* str */
/* PROGRAM-ID : callee2 */
static cob_field f_18 = {1, NULL, &a_1}; /* str */
static cob_field f_19 = {4, NULL, &a_2}; /* len */
/* LINKAGE SECTION (Items not referenced by USING clause) */
static unsigned char *b_19 = NULL; /* len */
The compute in callee1:
cob_decimal_set_field (&d0, cob_intr_length
(&f_12));
cob_decimal_get_field (&d0, &f_8, 0);
The compute in callee2:
cob_decimal_set_field (&d0, cob_intr_length
(&f_18));
cob_decimal_get_field (&d0, (f_19.data = ""
&f_19), 0);
So what's happening is that in callee2 variable 'b_19', which is
the address of the COBOL field 'len' is still set to NULL, and
thus we get a null pointer exception when trying to set it.
So it seems to me that even though the returning clause of the
procedure division is allowed syntactically its not actually
supported in the run-time. Bad news! :-(
Interestingly, a small kludge will make it work. I added the
following before any attempt to use the returning field (len):
set address of len to address of return-code
And now it works.
Comments?
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
open-cobol-list mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/open-cobol-list
|