* Help interfacing C @ 2000-07-25 0:00 Jes�s M. Mil�n-Franco 2000-07-25 0:00 ` Keith Thompson ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Jes�s M. Mil�n-Franco @ 2000-07-25 0:00 UTC (permalink / raw) Hi all. I have to do an Ada interface to a C library and I have found the following function declaration: int zzz_VaSend (zzz_mbox_cap mbox_c, int send_type, int flag, int len, char *buf , char *va_list, ...); Where va_list is a list with the receiver names finished by 'null', so the function has a variable number of parameters (the last is always null) Does anybody know if it is possible to have something similar in Ada ?? ---- Jesús M. Milán-Franco (milanjm@sip.ucm.es) Dpto. Sistemas Informáticos y Programación Facultad de Informática (U. C. M.) Ciudad Universitaria s/n - 28040 Madrid (Spain) phone: (+34) 91 394 43 50 / fax: (+34) 91 394 46 02 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Help interfacing C 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 ` Ken Garlington 2000-07-26 0:00 ` tmoran 2 siblings, 0 replies; 5+ messages in thread From: Keith Thompson @ 2000-07-25 0:00 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 1544 bytes --] "Jes�s M. Mil�n-Franco" <milanjm@inta.es> writes: > I have to do an Ada interface to a C library and I have found the > following function declaration: > > int zzz_VaSend (zzz_mbox_cap mbox_c, int send_type, > int flag, int len, char *buf , char *va_list, ...); > > Where va_list is a list with the receiver names finished by 'null', so > the function has a variable number of parameters (the last is always > null) > > Does anybody know if it is possible to have something similar in Ada ?? Not directly, at least not portably. A C function whose declaration includes a "..." token takes a variable number of arguments; the body of the function uses the facilities defined in the standard header <stdarg.h> to retrieve them. Ada has no such facility. (Overloading and default parameters can provide much of the same functionality, but that doesn't help much when you're trying to interface directly to a C function like this one.) You can define a list data structure that you can construct on the Ada side and pass to an intermediate C function, but even in C building a variable argument list from a list or array of values is tricky or even impossible. It's done with compiler magic. Your best bet is to find or create a function or set of functions that does what zzz_VaSend does, but without using "...". -- 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Help interfacing C 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 ` Ken Garlington 2000-07-26 0:00 ` tmoran 2 siblings, 0 replies; 5+ messages in thread From: Ken Garlington @ 2000-07-26 0:00 UTC (permalink / raw) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #1: Type: text/plain, Size: 694 bytes --] "Jes�s M. Mil�n-Franco" <milanjm@inta.es> wrote in message news:8ljlti$7u0$1@polaris.inta.es... > Hi all. > > I have to do an Ada interface to a C library and I have found the following function declaration: > > int zzz_VaSend (zzz_mbox_cap mbox_c, int send_type, > int flag, int len, char *buf , char *va_list, ...); > > Where va_list is a list with the receiver names finished by 'null', so the function has a variable number of parameters (the last is always null) > > Does anybody know if it is possible to have something similar in Ada ?? It's certainly possible to pass a list of items in Ada - what method do you use to get the elements of va_list? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Help interfacing C 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 ` Ken Garlington @ 2000-07-26 0:00 ` tmoran 2000-07-26 0:00 ` Keith Thompson 2 siblings, 1 reply; 5+ messages in thread From: tmoran @ 2000-07-26 0:00 UTC (permalink / raw) > 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. Or, since Ada allows easy creation of temporary arrays, you could do function f(some_params:some_type; list : array_type); and then call it with f(x, (1=>a)); -- perhaps replaced with something like the 1st f above. f(x, (a,b)); f(x, (a,b,c)); etc. Your function(s) will of course have to transmit their parameters appropriately to the C function. You will need separate pragma Imports for the C function for each number of parameters. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Help interfacing C 2000-07-26 0:00 ` tmoran @ 2000-07-26 0:00 ` Keith Thompson 0 siblings, 0 replies; 5+ messages in thread From: Keith Thompson @ 2000-07-26 0:00 UTC (permalink / raw) 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. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2000-07-26 0:00 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` Ken Garlington 2000-07-26 0:00 ` tmoran 2000-07-26 0:00 ` Keith Thompson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox