01-25-2010 04:33 PM
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.
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.
01-25-2010 04:59 PM
01-26-2010 04:29 AM
One more valid use cast of the type cast is to cast to the same type but a type def.
Felix
01-26-2010 05:17 AM
Ooops
you did write that... not my day...
Felix
01-26-2010 07:55 AM
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