LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How I get the right data type in CVI 8.0?

I expect a function cal from others, for example:
 
ShowTheCorrectDataType(Value);
{
     .............
}
 
But I do not know the type of the Value (int, char*, float ...) in-advanced, is there anyway we can define Value as Type T (any type) as in other languages? Please provide a link or a simple sample.
 
Thanks
0 Kudos
Message 1 of 2
(2,755 Views)
Unfortunately, C does not support templated functions or function overloading.  If you need a function to accept input of an unknown type, you can use a variable argument list:

int Foo (int type, ...);

or declare the parameter a void *:

int Foo (int type, void *value);


However, in either case, there is no builtin way of discerning the type of value that was actually passed.  This is why the type parameter is needed; this additional parameter makes it clear what type was actually passed.  This is how the Get/SetXXXAttribute functions in the CVI libraries work (the attribute parameter disabiguates the unknown type).

Using a variable argument list is probably a better option than a void * for input values because it does not require any extra work for the caller.  If you're not familiar with writing functions that take variable argument lists, take a look in a C reference or search the internet for va_list, va_start, va_arg, and va_end.  That should give you a good start.

If you have any problems, I'd be happy to help.

Mert A.
National Instruments

0 Kudos
Message 2 of 2
(2,750 Views)