[Top][All Lists]

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

Re: [open-cobol-list] static cobol 2 c : passing numeric data by referen

From: Gary Cowell
Subject: Re: [open-cobol-list] static cobol 2 c : passing numeric data by reference ?
Date: Fri Oct 21 02:19:00 2005

--- Xavier COUDIN <address@hidden> wrote:

> on the COBOL side, I write :
> 01 capsule.
>          02 phrase pic X(10).
>          02 c      pic 9999 VALUE 3 BINARY.
> and create the same structure in the C module
> typedef struct abcd {
>        char phrase[10];
>        int compteur ;
> } efgh;
> I can get the string without any problem.
> But the numerical value I get is completely wrong,
> nom atter of
> numerical type I declare on the C side (int / long /
> float / double).
> Any solution ?

It might be an alignment issue - compteur is not
guaranteed to follow phrase in storage, in fact with
10 bytes before it, there might be some padding in
there to align the int.

If you must pass the 01 level to C, receive it in C as
just 14 bytes of memory, then carve it up into your
structure afterwards with memcpy or somesuch.

You also try PRAGMAs to prevent structure padding but
this is not portable.

Oh and remember, if 'phrase' is a string, you'll need
11 bytes in C to hold it if you want to use things
like strlen on it because you need a null terminator.
Another good reason for not trying to pass strings
directly, but just pass as a lump of memory and carve
up the memory block as appropriate.

Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail

reply via email to

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