LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

varying number of arguments CVI 7.1

Hello,

 

anyone knows how it's possible to declare functions with a varying number of arguments in CVI 7.1? (later CVI versions can use C99 extension macro)

 

example: Func(int i, ... );

 

Thanks

0 Kudos
Message 1 of 8
(5,202 Views)

This is definitely possible by means of va_list and va_start macros: I have been using it since at least CVI5.

See this example program



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?
Message 2 of 8
(5,196 Views)

And what about macros?

 

example: #define MACRO(param1, ...)

0 Kudos
Message 3 of 8
(5,190 Views)

What do you mean with "macros"? va_start and va_arg already are macros, defined in stdarg.h



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 8
(5,185 Views)

I meant a self defined macro with variable arguments - here '...' doesn't work - you will get a compiler error because this is a C99 extension - you have to use __VA_ARGS__

 

example: #define MACRO(param1, __VA_ARGS__)

0 Kudos
Message 5 of 8
(5,167 Views)

Variable-length macros are supported only in CVI 9.0 and later.

 

Luis

0 Kudos
Message 6 of 8
(5,124 Views)

That's not right, you can use "__VA_ARGS__" instead of "..." for defining variable macro length...

0 Kudos
Message 7 of 8
(5,115 Views)

I'm not exactly sure what you mean. This is how you're supposed to use variable argument macros:

 

   #define debug_printf(format, ...) fprintf (stderr, format, __VA_ARGS__);
   debug_printf ("%s %s %s", "a", "b", "c");

 

You can do this in CVI 9.0 and later. You cannot do it in CVI 7.1.

 

You say that you can replace "..." with "__VA_ARGS__"? How, exactly? Like this?

 

   #define debug_printf(format, __VA_ARGS__) fprintf (stderr, format, __VA_ARGS__);
   debug_printf ("%s %s %s", "a", "b", "c");

 

That doesn't work in any version of CVI, so far as I know.

 

0 Kudos
Message 8 of 8
(5,099 Views)