Need urgent help....How to prototype a function 
Author Message
 Need urgent help....How to prototype a function

Hi Guys,
I have a unix/Micro focus question.
I had to make a call to system function mallinfo() which returns a
structure. The function is defined is unix as struct mallinfo
mallinfo(void ).

I defined the stru in working-storage and in procedure division
I called the function like following.
call "mallinfo" giving mallinfo-struc.

As I didn't proto type, compiler gives error.

Can any of you help me how to do that.

Thanks bunches.
Ramki

Disclaimer : If my employer shares my views,
I will be surprised



Tue, 13 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function

Quote:
>>Hi Guys,
>>I have a unix/Micro focus question.
>>I had to make a call to system function mallinfo() which returns a
>>structure. The function is defined is unix as struct mallinfo
>>mallinfo(void ).
>>I defined the stru in working-storage and in procedure division
>>I called the function like following.
>>call "mallinfo" giving mallinfo-struc.
>>As I didn't proto type, compiler gives error.
>>Can any of you help me how to do that.
>>Thanks bunches.
>>Ramki

>>Disclaimer : If my employer shares my views,
>>I will be surprised

Hello,  I believe I can help. You don't need to prototype anything - the
solution is simpler than that. First the structure to be passed needs to
be defined in the linkage section only. The call command format you are
using is incorrect. It should be -  call "mallinfo" using mallinfo-struc
with using in place of giving.

Hope this helps, richard



Wed, 14 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function

On 1997-01-24


:Hi Guys,
:I have a unix/Micro focus question.
:I had to make a call to system function mallinfo() which returns a
:structure. The function is defined is unix as struct mallinfo
:mallinfo(void ).

:I defined the stru in working-storage and in procedure division
:I called the function like following.
:call "mallinfo" giving mallinfo-struc.

:As I didn't proto type, compiler gives error.
:Can any of you help me how to do that.

You are calling a function with void arguments; it is returning the
address of the structure ( not the actual structure)  to you.  You cannot
have have assigned mallinfo-struc and address by defining it in the
working-storage section, it must be defined as a pointer in the linkage
section.  The memory space for mallinfo-struc is outside your program and
must be accessed through the linkage section.

Regards,
InstrJCC



Wed, 14 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function


Quote:
> >>I have a unix/Micro focus question.
> >>I had to make a call to system function mallinfo() which returns a
> >>structure. The function is defined is unix as struct mallinfo
> >>mallinfo(void ).

> Hello,  I believe I can help. You don't need to prototype anything - the
> solution is simpler than that. First the structure to be passed needs to
> be defined in the linkage section only. The call command format you are
> using is incorrect. It should be -  call "mallinfo" using mallinfo-struc
> with using in place of giving.

This is, at best, misleading.

struct mallinfo mallinfo(void)

must be done with

    CALL "mallinfo"
        RETURNING mallinfo-pointer

(it may be "C_mallinfo" required here, or similar).

The reurn from the C routine is a pointer, not the struct itself.
To access using a pointer it is necessary to define the struct in
LINKAGE SECTION and then relate this to the pointer using something
like SET ADDRESS OF mallinfo TO mallinfo-pointer

All non-standard of course.

Using a LINKAGE SECTION variable or record in a USING of a CALL
is not a good idea.  In my experience this causes crashes, YMMV.

But the main problem here is that a RETURNING is not the same as
a USING (and nor is GIVING) and the two are not interchangable.

In this case, as indicated by the C prototype given, a RETURNING
is the only way to get the data.



Wed, 14 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function


Quote:

> I had to make a call to system function mallinfo() which returns a
> structure.  The function is defined in unix as struct mallinfo
> mallinfo(void).

> I defined the struct in working-storage, and in the procedure division
> I called the function like following.
>     call "mallinfo" giving mallinfo-struct.

> As I didn't proto type, compiler gives error.

CoBOL does not have prototyping and structure-valued functions do not fit
well into CoBOL.  Write yourself a wrapper in C like this:

    $ cat>mallinfo_wrapper.c
    #include <malloc.h>
    #include <string.h>
    void mallinfo_wrapper(void *working_storage)
    {
        struct mallinfo mallinfo_struct=mallinfo();
        (void) memcpy(
            working_storage,
            &mallinfo_struct,
            sizeof(mallinfo_struct));
        return;
    }
    ^D
    $ cc -c mallinfo_wrapper.c

Then call from CoBOL like this:

    call "mallinfo_wrapper" using by reference mallinfo-struct.

--
Christopher Westbury, Midtown Associates, 15 Fallon Place, Cambridge, MA 02138



Thu, 15 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function


Quote:

> struct mallinfo mallinfo(void)

> must be done with

>     CALL "mallinfo"
>         RETURNING mallinfo-pointer

> (it may be "C_mallinfo" required here, or similar).

> The return from the C routine is a pointer, not the struct itself.

Sorry, this is incorrect.

There are many Unix routines that _do_ return a pointer to a struct, and
those routines can be handled exactly as you suggest.  You can recognize
a pointer-valued function by the star in the declaration, for example:

    struct tm *localtime(const time_t *clock);

However, struct mallinfo mallinfo(void) is a structure-valued function.
It returns the struct itself, in a highly implementation-dependent
manner, not a pointer to the struct.

--
Christopher Westbury, Midtown Associates, 15 Fallon Place, Cambridge, MA 02138



Fri, 16 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function


Quote:

> You are calling a function with void arguments; it is returning the
> address of the structure (not the actual structure) to you.

Sorry, this is wrong.  mallinfo() is not a pointer-valued function.  As
the original poster correctly stated, mallinfo() is a structure-valued
function.

--
Christopher Westbury, Midtown Associates, 15 Fallon Place, Cambridge, MA 02138



Fri, 16 Jul 1999 03:00:00 GMT  
 Need urgent help....How to prototype a function


Quote:

> [errors snipped]

> Hope this helps, richard

Hope is a poor substitute for taking a few seconds to check the facts
before posting to hundreds of thousands of sites around the world.

--
Christopher Westbury, Midtown Associates, 15 Fallon Place, Cambridge, MA 02138



Fri, 16 Jul 1999 03:00:00 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. URGENT-help needed-URGENT

2. Need CW Prototype equivalent for VB function

3. Clarion function prototypes for SPGP pgp wrapper functions

4. Help needed with this prototypes

5. URGENT: need Fortran functions IDed

6. Identification of functions needed- URGENT

7. Help (urgent): FILEINF function in VMS to UNIX

8. Functions attributes accessed from within the function definition URGENT please

9. URGENT: Need help with AND binary operation in awk

10. urgent! need help with database bindings

11. Need Help on awk!!!! **** Urgent ****

12. 2nd post Urgent: Need help with FM2.9!

 

 
Powered by phpBB® Forum Software