cast - Change data type of object in Embedded IDE Link™ CC

Syntax

objname2 = cast(objname,datatype)
objname2 = cast(objname,datatype,size)

Description

objname2 = cast(objname,datatype) returns objname2, a copy of objname, whose represent, storagepervalue, and wordsize properties are changed so objname2 supports the data type specified by datatype. Input argument datatype can be any supported data type. After the cast operation, read or write operations apply the appropriate data conversion to implement on your target the data type specified by the represent, storagepervalue, and wordsize properties of objname2.

The following data types work as input arguments to cast.

datatype Stringrepresent Property Value

'double'

'float'

'single'

'float'

'int32'

'signed'

'int16'

'signed'

'int8'

'signed'

'uint32'

'unsigned'

'uint16'

'unsigned'

'uint8'

'unsigned'

'long double'

'float'

'float'

'float'

'long'

'signed'

'int'

'signed'

'char'

'signed'/'unsigned'

'unsigned long'

'signed'

'unsigned int'

'unsigned'

'unsigned char'

'unsigned'

'Q0.15'

'fract'

'Q0.31'

'fract'

Various Texas Instruments™ processors restrict the sizes of the data types used by objects in Embedded IDE Link CC. Shown in the next table, the processor families restrict the valid word sizes for the listed data types.

represent Property ValueC5000™ Processor Word Size LimitsC6000™ Processor Word Size Limits

'float'

32, 64 bits

32,64 bits

'signed'

16, 24, 32, 40, 48, 56, 64 bits

8, 16, 24, 32, 40, 48, 56, 64 bits

'unsigned'

16, 24, 32, 40, 48, 56, 64 bits

8, 16, 24, 32, 40, 48, 56, 64 bits

'binary'

16, 24, 32, 40, 48, 56, 64 bits

8, 16, 24, 32, 40, 48, 56, 64 bits

'fract'

Using the properties of the objects, you change the word size by changing the value of the storageunitspervalue property of the object. Note that you cannot change the bitsperstorageunit property value, which depends on the processor and whether the object represents a memory location or a register.

cast applies to any object that has the represent, storagepervalue, and wordsize properties. function, ticcs, and rtdx objects do not use the represent property and do not support cast.

A note — you could change the properties for objname2 directly with set when you work with less common data types. Generally, we recommend you use cast to change the data type for an object, and consider convert as well.

objname2 = cast(objname,datatype,size) returns objname2, a copy of objname, with the specified data type for the represent, storagepervalue, and wordsize properties, and the size property value set to size. For bitfield objects, size is always 1.

Using cast with pointer and rpointer Objects

Working with pointer objects and register pointer (rpointer) objects is slightly different from using cast with numeric objects.

When you cast a pointer object, the results depend on the data type you specify to cast to in the syntax:

Examples

If your project includes the variables used in the three examples that follow, try them out to see cast at work. Without the specified variables, the examples do not run — read the examples to see the input and output from cast.

Cast the Data Type from int16 to Q0.31

After you create a ticcs object, use cast to recast a variable from data type int16 to Q0.31.

Create the int16 indirectly because you cannot create handles to int16 data types in one step:

g_int16=createobj(cc,'g_float')
convert(g_int16,'int16')
cast(g_int16,'Q0.31')

Cast the Data Type from signed char to Q0.15

After you create a ticcs object, use cast to recast a variable from data type signed char to Q0.15.

Create the unsigned char from a signed char and cast from there to Q0.15:

g_uchar=createobj(cc,'g_schar')
cast(g_uchar,'Q0.15')

Cast the Data Type from double to uint32

After you create a ticcs object, use cast to recast a variable from data type double to uint32.

Create the double data type variable and cast it to a uint32:

g_double=createobj(cc,'double')
cast(g_double,'uint32')

See Also

convert

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS
 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS