[Info-vax] COBOL PIC format for a 64 bit unsigned int ("long long") ?

Jan-Erik Söderholm jan-erik.soderholm at telia.com
Tue Oct 13 06:24:23 EDT 2009


glen herrmannsfeldt wrote:
> Jan-Erik S?derholm <jan-erik.soderholm at telia.com> wrote:
> < Jim Duff wrote:
> <> Jan-Erik S?derholm wrote:
> <>> I am trying to call some COBOL code from a piece of C...
> 
> <>> The call from C looks like this :
> 
> <>>  char cob_inart[16];
> <>>  unsigned long long cob_insernr;
> <>>  char cob_utben[16];
> <>>  char cob_utordnr[16];
> <>>  int rc;
> 
> <>>  rc = MES101(cob_inart, cob_insernr, cob_utben, cob_utordnr);
> 
> <>> I get a ACCVIO when trying to use the "unsigned long long"
> (snip(
>  
> < Outputs "INART" (as expected) and then ACCVIO's on the
> < second DISPLAY. Anyway, see below...
>  
> (snip, I wrote)
>  
> < > I don't know specifically about COBOL, but calls from C to
> < > many other languages expect the address of, not the value of,
> < > the arguments.  For arrays that happens sort of automatically
> < > (an array name is a constant pointer to the first element),
> < > but not for scalars.  Try an & in front of the non-array.
>  
> (snip) 
> < And also for my original code. I changed the type of the
> < "unsigned long long" variable into a "pointer to unsigned
> < long long", but the effect is the same...
> 
> No, that doesn't help and probably makes it worse.

It worked.

> Did you allocate any memory for the pointer to point to?

I assigning the pointer the value of another pointer
pointing to a "long long" with the actual value.
I didn't *allocate* anything myself, doesn't the pointer
gets allocated by the pointer variable declaration ?

> Did you add * to all references to it?
 > Instead, just put an &
> in front of non-array arguments in the call.

The same thing as actualy using a pointer as paramater in
the first place, not ?

> 
>   rc = MES101(cob_inart, &cob_insernr, cob_utben, cob_utordnr);
> 
> That tells C to pass the address of (a pointer to) cob_insernr
> instead of the value.

Yes, if cob_insernr isn't already a pointer by itself, not ?
In that case it can (and should) be used without the "&".

Right now I have :

struct inval_struct {
       char *inart;
       unsigned long long  *insernr;
};


int my_func(struct soap          *soap,
             struct inval_struct  *input_values,
             struct retval_struct *return_values)
{

         unsigned long long *cob_insernr;
         int rc;

         cob_insernr = input_values->insernr;
         rc = MES101(cob_inart, cob_insernr, cob_utben, cob_utordnr);

I guess I could also use "input_values->insernr" directly as
paramater in the call to MES101 without going through
cob_insert, but that's another thing...

Apart from the fact that the above might not be "nice C",
is there any real error now ?

Jan-Erik.





More information about the Info-vax mailing list