libffcall
[Top][All Lists]
Advanced

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

Re: Please help me understand va_alist


From: Bruno Haible
Subject: Re: Please help me understand va_alist
Date: Thu, 06 Feb 2020 13:30:11 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-171-generic; KDE/5.18.0; x86_64; ; )

Hi,

> after several trials and errors I was able to get ffcallback to work.
> However I don't understand how to use va_alist and how to adapt it for
> my own use case beyond the basic examples that I've copy-pasted.
> Consider this snippet, for example, taken from "ffcall/callback/tests.c":
> 
>     void i_i_simulator (void* data, va_alist alist)
>     {
>       va_start_int(alist);
>      {int a = va_arg_int(alist);
>       int r=a+1;
>       fprintf(out,"int f(int):(%d)",a);
>       fflush(out);
>       va_return_int(alist, r);
>     }}
> 
> what do va_start_int and va_return_int do? The manpage has them defined like 
> this:
> 
>     va_start_type(alist[, return_type]);
>     arg = va_arg_type(alist[, arg_type]);
>     va_return_type(alist[[, return_type], return_value]);
> 
> but what are all those optional return_type/return_value arguments and what 
> are they used for?

As written in callback.html:

  arg = va_arg_type(alist[, arg_type]);

  fetches the next argument from the argument list.

  va_return_type(alist[[, return_type], return_value]);

  ends the walk through the argument list and specifies the return value. 

int a = va_arg_int(alist);

fetches the next argument, assuming it is of type 'int'.

va_return_int(alist, r);

stores r as the return value of the call, assuming the return type is of
type 'int'.

> Finally, what if one of my functions accepts a "struct" as argument insted of 
> int? Should I use "va_start_struct_mystruct"?

Yes, to fetch a 'struct mystruct' argument, you'll use

  struct mystruct a = va_arg_struct (alist, struct mystruct);

Bruno




reply via email to

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