LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is 2nd arg for va_arg if passed parm is ptr to struct?

Another department has defined the prototypes with a variable list of pointers to structures. I'd like to use the va_start, va_arg, ... functions. What should the second argument be to va_arg? CVI doesn't seem to like anything I try.
0 Kudos
Message 1 of 4
(3,051 Views)
It's your task to declare the correct type of struct to pass to the function. Inside the function you must first cast the pointer to the appropriate structure and then you can use it normally.

Please take a look at this simple project in which a function declared with variable arguments list is passed some variables and a struct.

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,051 Views)
Your example passes the contents of 1 structure as ints and doubles and characters along with a list that defines the structure. It does not address the issue of passing pointers to structures, let alone multiple pointers to multiple structures.
Your line 110, va_arg (ap, dummy *); produces a compiler error: operands of * have illegal types "pointer to struct dummy" and "int".

I have since found a work around for
void function(struct DPD *parm,...) using a
union {
struct DPD *ptr;
int pointer;
} x;
with va_start(marker, x.pointer); and x.pointer=va_arg(marker,int); which fakes the compiler into thinking I'm passing integers instead of pointers.
I was hoping for a more politically correct method.
0 Kudos
Message 3 of 4
(3,051 Views)
I had no compiler error in developing the project: I'm using cvi 6.0, which compiler are you using?

As per the address subject, I should be passing and using the pointer returned by malloc function. Infact, to address internal components of the structure I am using the indirect selector '->' instead of the direct selector '.'. According to C syntax, the expression dd->Dprm is precisely equivalent to the expression (*dd).Dprm.

But anyway, when treating pointers there always seems to be something too thin for me to catch...


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(3,051 Views)