Studio:Scl cast: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
m (Text replace - 'Category: SCL' to 'Category:Studio:SCL')
 
(2 intermediate revisions by 2 users not shown)
Line 40: Line 40:
* scl_cast() can be used to cast a data item of type void* to a union type, if all members of the union are of type pointer.
* scl_cast() can be used to cast a data item of type void* to a union type, if all members of the union are of type pointer.
* scl_cast() cannot be applied to bit fields.
* scl_cast() cannot be applied to bit fields.
* An error will result if scl_cast() is applied to a set of runtime values that intersects with the set of values explicitly specified by any pragma that has appeared earlier (by way of lexical position) in the source code. In other words, scl_cast() cannot be used to "cast away" information conveyed by previous pragmas. (Refer to section 1.2.16, Absolute Specifiers, in the [http://www.s2technologies.com/pdf/s2sSCLReferenceGuide.pdf STRIDE SCL Reference Guide] for a description and definition of runtime value sets.)
* An error will result if scl_cast() is applied to a set of runtime values that intersects with the set of values explicitly specified by any pragma that has appeared earlier (by way of lexical position) in the source code. In other words, scl_cast() cannot be used to "cast away" information conveyed by previous pragmas. (Refer to section 1.2.16, Absolute Specifiers, in the [[Media:s2sSCLReferenceGuide.pdf|SCL Reference Guide]] for a description and definition of runtime value sets.)


== Examples ==
== Examples ==
Line 69: Line 69:
</source>
</source>


[[Category: SCL]]
[[Category:Studio:SCL]]

Latest revision as of 00:10, 21 August 2009

The scl_cast pragma

Constraining is the transformation of a data type so that it behaves like another data type. There are two forms of constraining: type constraining and value constraining.

Type constraining, as in the C language, has a source type and a destination type. The source type is the data type that is originally specified (e.g., written in the header file). The destination type is the data type into which the source type is being transformed.

The scl_cast pragma is used for type constraining. It would commonly be used to map enumerations to other types, or to map a void pointer. The STRIDE host environment treats the constrained (or casted) field as if it were the new type, but the original type size is maintained.

Syntax

The following form changes the type inside the specified container (the function or structure):

#pragma scl_cast(global-type-specifier, cast-type)

The following form changes the type globally:

#pragma scl_cast(container-specifier, field-specifier, cast-type)
Parameters Type Description
container-specifier String Name of the container of the field to be cast
field-specifier String Name of the field to be cast
cast-type String Name of the new type for the cast result
global-type-specifier String Name of the global type to be cast

Notes

  • scl_cast() can only be used to cast items that are of exactly the same size.
  • scl_cast() can only be applied to the integral type and pointer type instances, or typedef names for integral types or pointer types. The type-specifier must designate a pointer type or integral type.
  • scl_cast() can be used to cast a data item of type void* to a union type, if all members of the union are of type pointer.
  • scl_cast() cannot be applied to bit fields.
  • An error will result if scl_cast() is applied to a set of runtime values that intersects with the set of values explicitly specified by any pragma that has appeared earlier (by way of lexical position) in the source code. In other words, scl_cast() cannot be used to "cast away" information conveyed by previous pragmas. (Refer to section 1.2.16, Absolute Specifiers, in the SCL Reference Guide for a description and definition of runtime value sets.)

Examples

Example 1

int func(void *p); 

#pragma scl_function(func)
#pragma scl_cast(func, p, int *)

Example 2

typedef unsigned int u32_t; 
typedef enum 
{
  ONE = 1, 
  TWO = 2, 
  THREE = 3
} numbers_e; 

// cast occurrences of u32_t to numbers_e
#pragma scl_cast(u32_t, numbers_e)

int func(u32_t x); 
#pragma scl_function(func)