| Embedded IDE Link™ CC | ![]() |
objname2 = cast(objname,datatype)
objname2 = cast(objname,datatype,size)
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 String | represent 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' |
Note pointer and rpointer objects respond differently when you use cast. Refer to Using cast with pointer and rpointer Objects for more information about the supported data types for pointer or rpointer objects. |
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 Value | C5000™ Processor Word Size Limits | C6000™ 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.
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:
When you specify a valid pointer type for your new pointer or rpointer object, cast creates the new pointer or rpointer object as a pointer type. Valid pointer data types are datatype * — include the asterisk to indicate this is a pointer.
When you specify a nonpointer data type for your new object, cast creates a new object that is no longer a pointer and does not access the referent that the original object accessed. Trying to cast to a nonpointer data type causes an error in MATLAB® software. Data types that do not support pointers are
All ANSI® C native data types without the asterisk that indicates this is a pointer
enum (enumerated)
string
struct
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.
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')
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')
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')
![]() | build | ccsboardinfo | ![]() |
| © 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 |