LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Weekly Nugget 01/25/2010

There was a plethora of great information about the reference data type discussed in this thread recently, but I'd like to focus on one detail in particular for this week's nugget. 

 

As a general rule, you never want to type cast a reference of one type into a reference of another type.  If you're ever casting references, you're probably doing it for comparison or storing reasons, and as a result, you should probably be casting to/from an integer data type.  Casting a reference into another reference can often lead to instabilities and/or crashes.

 

reference_casting.png

 

The one exception to this rule is if you're casting a reference to/from a typedefed reference of the exact same type.  This is one of the specific cases described in the link above.

 

To help detect potential problems with dissimilar data type reference casting, I plan on shipping a test with a future version of the VI Analyzer Toolkit for this situation.

Message 1 of 5
(5,456 Views)
Note that this technique of casting a reference to an integer probably makes the code not work on any 64-bit LabVIEW platforms. I've never tested it, but I would guess the references are 64-bit.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 5
(5,437 Views)

One more valid use cast of the type cast is to cast to the same type but a type def.

 

Felix 

Message 3 of 5
(5,345 Views)

Ooops Smiley Surprised

 

you did write that... not my day...

 

Felix 

 

 

Message 4 of 5
(5,331 Views)

Ok since I played a part in stirring up this mud-puddle, let stomp around and see if I splash anyone else.

 

What my my placed type cast showed was a couple of interesting thoughts.

 

1) My crashing only showed up when shutting down and even though I type cast to the wrong type, the code worked!

 

Mud:

a) LV can still work the Class data (cluster) even though I lied to it about what type it was... so the type plays a part in deallocating resource but is not used othrwise!

 

b) Since all of this worked without crashing (till the end) there appeared to no moving of the data... LVOOP wires really act like pointers to static data structures.

 

Yes the "mud" above is wild speculation and I am not encouraging illegal type-casting. I am only commenting on what I found while examining the wreckage.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 5
(5,284 Views)