LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
MKsarith

Indexing the empty array

While taking the zeroth index of an empty array of Enum, it is giving the default value of Enum as output.

If it is an empty array, it should give an empty enum type, instead of giving default value of enum as zeroth index of the empty array.

8 Comments
Manzolli
Active Participant

For me looks like it's working properly.

 

With an empty array of numbers the result will be zero, for string the result is an empty string, even if the default value is changed.

 

For numbers it could result in a NaN, but what result we would expect from a empty array of strings? NI would create a "NaS" standing for "Not a String"? But what LabVIEW should do with all other kind of empty arrays?

André Manzolli

Mechanical Engineer
Certified LabVIEW Developer - CLD
LabVIEW Champion
Curitiba - PR - Brazil
MKsarith
Member

Like Nan and Nas they should create some indication to show that its an empty array.

Now Empty array is meaningless, because it contains a value. They can maintain the data type, but the index value should give a feeling that , we are reading the index of an empty aray.

Norbert_B
Proven Zealot

An empty array doesn't contain ANY element, there is no value to read. It is a foundational functionality of LV to return the default value of the datatype in such a situation.

As enum is an integer type, it will return '0'.

 

The behavior is both "works as expected" and "works as intended".

 

Norbert

 

EDIT: It sounds like you want to have Index Array to have an Error Out connector and it will create at least a warning if you index an invalid item.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
MKsarith
Member

@Norbert:  Yes. Otherwise it can show as 'empty' with the same data type (like, NaN)

tst
Knight of NI Knight of NI
Knight of NI

I really wouldn't like this. If you start adding "not a boolean", "not an enum", etc. to each data type, you will both have to define how each primtive function behaves when taking that value and you will have to account for it everywhere you use the data type (you can be almost certain that there are places in your code where your code will start a cascade reaction of failures if it somehow gets a NaN you didn't anticipate).

 

If it's really important not to accept empty arrays, then use the Empty Array? primitive and handle it. In many places, an empty array is actually a perfectly valid value and indexing an out of bounds value is also valid.


___________________
Try to take over the world!
ToeCutter
Active Participant

Anything that adds overhead to the array indexing process is bad news. You could always create your own wrapper to introduce error functionality if you want.

AristosQueue (NI)
NI Employee (retired)

MKsarith there is no such thing as an empty enum type in LV. An enum wire may contain only the values defined in the enum. No more, no less. Ever. The default value of an enum is the zeroth value of the enum, and the Index Array prim returns the default value of the array's data type.

 

This is correct behavior, fully intended, and will not be changed.

Darren
Proven Zealot
Status changed to: Declined