LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

An error that I can not correct

Helpplease:

Someone will be kind enough to help me fix this problem?

 

Thant you

0 Kudos
Message 1 of 6
(2,877 Views)

hello

 

your problem is in the h file where you declered the structure of the 'index' variable

0 Kudos
Message 2 of 6
(2,860 Views)

Thank you

 

Here is how I declared it in h

0 Kudos
Message 3 of 6
(2,858 Views)

That's not a structure: it's an enumeration.

You can declare it as an int in the function definition (you are already using it as an int when you write Bench_Info_Item[index])

 

Additionally, you should initialize the enum:

typedef enum {
   No_Item = 0,
   Bench_Name,
   Bench_Number,
...
} BenchInformationIndex;


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 6
(2,828 Views)

Be extremely careful when using enums as array indices. Code like Bench_Info_Item[index-1] with index==0 might not be caught by the compiler and may only surface during debugging runs. Or the program works as expected but every now and then it does something weird.

Also: adding, and thus renumbering, the enum with No_Item=0 might cause issues if the enum is used to reference ring control entries or other things. Or somewhere else there's a hard coded Bench_Info_Item[0]=...

 

Clang has many warnings for enum issues but it's not bullet proof.

 

As a side note, taken from a C89 draft:

3.5.2.2 Enumeration specifiers

[...]

If the first enumerator has no = , the value of its enumeration constant is 0. Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant.

[...]

Each enumerated type shall be compatible with an integer type; the choice of type is implementation-defined.

-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 5 of 6
(2,792 Views)

Thanck you!

0 Kudos
Message 6 of 6
(2,712 Views)