[Top][All Lists]

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

Re: Please help me understand va_alist

From: Name Surname
Subject: Re: Please help me understand va_alist
Date: Thu, 6 Feb 2020 16:32:19 +0100

Thank you, I think I'm getting the gist of it. I think the man is a bit 
confusing because va_start_type or va_arg_type functions are defined in the 
source as va_arg_int(LIST) and using va_arg_type(alist[, arg_type]) in the 
manual seems to suggest that it expect an additional parameter?

Anyway, I still have an issue wrt va_start_type. I don't fully understand the 
purpose of _type in the va_start macro since it doesn't seem to return 
anything. For instance, even if my function does not define any argument, int 
func(void), I get an error if I use va_start_void/va_return_int combination 
(vacall: va_start type 0 and va_return type 6 disagree.). It does seem to work 
though if I match the types, va_start_int/va_return_int, but I don't understand 


ps: if it's any useful, I'm using the ffcall library from Debian (oldstable) 
that appears to be v1.10

Sent: Thursday, February 06, 2020 at 1:30 PM
From: "Bruno Haible" <address@hidden>
To: address@hidden
Cc: "Name Surname" <address@hidden>
Subject: Re: Please help me understand va_alist

> 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);


reply via email to

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