gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] nested call statements, best practices


From: Michael Anderson
Subject: Re: [open-cobol-list] nested call statements, best practices
Date: Tue, 17 Sep 2013 13:11:54 -0500
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8

There is a cobc directive for that.
-fnull-param Pass extra NULL terminating pointers on CALL statements

OR, What I do for this situation:

Working Storage.
 1 astring pic x(32000).
 1 bstring pic x(24) value "       asdfgh           ".

Procedure Division.
 begin.
        String trim(bstring) X"00" Delimited by size into astring.

NOTE: MOVE pads with trailing spaces, where STRING does not!
After the above "STRING" statement, 'astring' contains 'asdfgh' followed by a single null byte, followed by 31k bytes of "Who the heck knows". But the remainder 31k bytes does not matter in C, because when you pass it to C everything after the NULL is ignored, but you could initialize it to something.
Something like LOW-VALUES, which is all NULLS, in which case you could just:

        Move Low-Values To astring.
        String trim(bstring) Delimited by size into astring.

Now 'astring' contains 'asdfgh' followed by a 31k null bytes, if you had used MOVE instead, you'd have 'asdfgh' followed 31k of spaces. Using STRING, not MOVE, and Passing astring to a C function, the C function see's only 'asdfgh', but the C function should allow space for at least one null character at the end.

Maybe Brian could write an example of a OpenCobol 2.0 function to do this, but it would require OpenCobol 2.0,
I'd like to see what 2.0 functions look like.




On 09/17/2013 12:27 PM, Patrick wrote:
Thanks Michael

I was thinking about reposting, there was missing information I should have included and the mailing list reformatted my code so it was really hard to read.

Here is what I am trying to do in non-Cobol-ish pseudo code

Example 1:

cFunction = would be a call statement calling cFunction
cob-str-to-C = a utility to trim strings and append nul byte
incompatible = a picture based Cobol string

cFunction ( cob-str-to-C ( incompatible ) )



I know I could do something like


Example 2

temp = cob-str-to-C ( incompatible )

CFunction ( temp )

But then I have to use Cobol storage for the output of cob-str-to-C and that might be an issue. i was thinking that a nested call result would not have to be passed back into the PICTURE based system..

Does this make any more sense? Sorry to everyone for the last post.

Thanks








reply via email to

[Prev in Thread] Current Thread [Next in Thread]