comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: Help interfacing C
Date: 2000/07/26
Date: 2000-07-26T00:00:00+00:00	[thread overview]
Message-ID: <yecd7k0zmsl.fsf@king.cts.com> (raw)
In-Reply-To: jSGf5.29$LV1.41447@news.pacbell.net

tmoran@bix.com writes:
> > int  zzz_VaSend (zzz_mbox_cap mbox_c, int send_type,
> >                  int flag, int len, char *buf , char *va_list, ...);
> 
> You could use overloading
>   function f(some_params:some_type; a:another_type);
>   function f(some_params:some_type; a,b:another_type);
>   function f(some_params:some_type; a,b,c:another_type);
> That works well if you usually only have a few items in the variable
> parameter list.

If the overloaded function f is interfaced directly to zzz_VaSend(),
this will work only if the C implementation passes ordinary arguments
and variable (stdarg) arguments the same way.  This is probably true
of many, but not all, implementations.

On the other hand, assuming a C function like this:

    int f(some_type arg1, ...);

you could do something like this:

    function F1(Arg1: Some_Type)
        return Interfaces.C.int;
    pragma Import(C, F1);

    function F2(Arg1: Some_Type; Arg2: Another_Type)
        return Interfaces.C.int;
    pragma Import(C, F2);

    function F3(Arg1: Some_Type; Arg2, Arg3: Another_Type)
        return Interfaces.C.int;
    pragma Import(C, F3);

    -- Use renaming declarations to overload F1, F2, F3 as F

and in C:

    int f1(some_type arg1)
    {
        return f(arg1);
    }

    int f2(some_type arg1, another_type arg2)
    {
        return f(arg1, arg2);
    }

    int f3(some_type arg1, another_type arg2, another_type arg3)
    {
        return f(arg1, arg2, arg3);
    }

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Welcome to the last year of the 20th century.




  reply	other threads:[~2000-07-26  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-25  0:00 Help interfacing C Jes�s M. Mil�n-Franco
2000-07-25  0:00 ` Keith Thompson
2000-07-26  0:00 ` tmoran
2000-07-26  0:00   ` Keith Thompson [this message]
2000-07-26  0:00 ` Ken Garlington
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox