Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Type Cast

LabVIEW 8.2 Help
August 2006

NI Part Number:
371361B-01

»View Product Info

Casts x to the data type, type, by flattening it and unflattening it using the new data type. The connector pane displays the default data types for this polymorphic function. Details  

type is the data type to which you want to convert the data.
x is the data you want to convert to type. x can be any data type.
*(type *) &x is the value provided in x and converted to the same data type as type.

Type Cast Details

This function can generate unexpected data if x and type are not the same size. If x is of a larger data type than type, this function uses the upper bytes of x and discards the remaining lower bytes. If x is of a smaller data type than type, this function moves the data in x to the upper bytes of type and fills the remaining bytes with zeros. For example, a U8 with value 1 type cast to a U16 will result in a value of 256.

If you want to upcast or downcast references, use the To More Generic Class and To More Specific Class functions instead of the Type Cast function. The Type Cast function does not provide error checking, but the To More Generic Class and To More Specific Class functions do. The To More Specific Class function has error in and error out parameters. The To More Generic Class function breaks the wire at edit time when you wire a reference to an incompatible target class.

If x might contain Boolean data created with LabVIEW 4.x or earlier, right-click this function and select Convert 4.x Data from the shortcut menu to convert the data to a format that is readable by LabVIEW 5.0 and later. In Convert 4.x Data mode, this function interprets x as if the data is stored in LabVIEW 4.x data storage layout and displays the icon for this function with a red 4.x on it. LabVIEW 4.x and earlier stores Boolean data in two bytes unless the data is in an array, in which case LabVIEW stores each Boolean element in a single bit. LabVIEW 5.0 and later stores Boolean values in a single byte, regardless of whether it is in an array. National Instruments recommends reworking any application that uses the Convert 4.x Data mode as a long term solution.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit