LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI 9 Problems

hi all, just got the CVI 9.0 and checked the C99-possibillities. some useful things, but especially the "inline" qualifier doesnt do anything ? and two question regarding the following lines: 1. why crashes the line "struct s1 someObjects[3]={[2].a=345,[0].b=8.97};" CVI down ? 2. I built a fct with variable arg-len. how to recognize that there are no more arguments in the fct-call ? ( I worked arround with a THRESHOLD. ) thanks and best regards Simon /****************************************************** * * C99-Features of CVI 9 * ******************************************************/ #include #define THRESHOLD 0.01 //A Fct with variable ArgLen double addAll(double,...); //Main int main (int argc, char *argv[]) { struct s1 { int a; double b; char c; }; //CVI crashes ??? struct s1 someObjects[3]={[2].a=345,[0].b=8.97}; printf("%lf\n",addAll(1.23, 2.34, 5.67)); return 0; } double addAll(double oneFixedIsNeccesary, ...) { double summe=0; double lfArgument; va_list l_Arg; //Setze den Startpunkt der Liste va_start(l_Arg,oneFixedIsNeccesary); summe=oneFixedIsNeccesary; //CVI How to recognize that nomore argument is available ??? do { lfArgument=va_arg(l_Arg,double); summe+=lfArgument; }while(lfArgument > THRESHOLD); return summe; }
0 Kudos
Message 1 of 2
(3,208 Views)

The crash you found is a bug. It is related to runtime pointer checking support for the array. It occurs when you have an array of structures, and you use designated initializers to initialize a struct member, followed by an designator for the enclosing array (i.e. { [2].a=345, [0].b=8.97 }) Unfortunately there is no workaround besides disabling the runtime pointer checking (from Options>>Build Options, set Debugging level to "No run-time checking" ). I've filed a bug report to have this fixed in a future release.

 

Though the inline keyword will not result in any actual function inlining, it is supported semantically. It results in something very similar to a static declaration. This is provided for the sake of using existing header files that declare inline functions.

 

A function with a variable number of arguments must have some way of knowing the number and types of the arguments that will be passed. For example, many CVI library set attribute functions (e.g. SetCtrlAttribute) take a variable argument list and use the passed attribute specifier to determine how many and what types of arguments to expect. Your function could take parameters to specify the number/types of variable arguments, or in some cases you can use a special reserved value to indicate the end of the parameter list. For example:

 

MakeStringList("hello",  "world", 0);

MakeStringLIst("little", "bunny", "foo", "foo", 0);

 

In this case, because 0 is not a valid string value, it can be used to indicate the end of the list. The function MakeStringList would keep reading char * arguments until it read one that was equal to 0.

 

Mert A.

National Instruments

0 Kudos
Message 2 of 2
(3,176 Views)