Studio:Scl values: Difference between revisions
Jump to navigation
Jump to search
Line 79: | Line 79: | ||
== See Also == | == See Also == | ||
* For additional information on the scl_values pragma, including constraints, refer to the section on scl_values in the | * For additional information on the scl_values pragma, including constraints, refer to the section on scl_values in the [http://www.s2technologies.com/pdf/s2sSCLReferenceGuide.pdf SCL Reference Guide]. | ||
[[Category: SCL_Reference]] | [[Category: SCL_Reference]] |
Revision as of 00:48, 2 October 2008
The scl_values pragma
The scl_values pragma allows a data item to be constrained to a particular set of values.
Syntax
#pragma scl_values(global-type-specifier, values-type) #pragma scl_values(container-specifier, field-specifier, values-type) #pragma scl_values(container-specifier, field-specifier, values-value-1, values-value-2..n) #pragma scl_values(global-type-specifier, values-value-1, values-value-2..n)
Parameters | Type | Description |
global-specifier | String | Name of the global type to be constrained. |
values-type | String | Name of the type that enumerates the range of values to which the data item is constrained. |
container-specifier | String | Partial identification of the field to be constrained. The container_specifier in combination with the field_specifier completely identify the field to be constrained. |
field-specifier | String | Together with the container specifier, completes the identity of the field whose values are to be constrained. |
values-value-1 | Constant expression | First constant expression to which the data item's value will be constrained. |
values-value-2..n [Optional] | Constant expression list | Optional second and subsequent constant expressions, adding to the set of values to which the data item's value will be constrained. These expressions must be comma separated. |
Notes
- The scl_values pragma may only be applied to items that are of integral type (e.g., signed/unsigned char, short, int, and long), and pointers that have had scl_ptr_opaque applied to them.
- Each value in the values list is assigned both a symbolic name and an integral value. The symbolic name is:
- The macro name if the value is defined by a macro (the macro name must be a non-parameterized macro).
- The enumerated constant name if the value is an enumeration constant.
- If the constant is not a simple macro name or enumerated constant name (i.e., it is some kind of expression) then the name is the constant expressed as a decimal number, including its sign if the value is negative.
- Two values in the number-list may not have the same symbolic name.
- scl_values() does not change the underlying type of the instances to which it is applied. If those instances are referenced by other pragmas, the type is unaffected; however, the instances will have constrained values.
Examples
Example 1: Integer field constrained to enumeration values
typedef enum {
RED,
GREEN,
BLUE
} COLOR;
int f(int x);
#pragma scl_function(f)
#pragma scl_values(f.x, COLOR)
Example 2: Integer field constrained to a specific set of integer values
#define FIRST 23
#define SECOND 44
#define THIRD 50
#define FOURTH -5
int f(int x);
#pragma scl_function(f)
#pragma scl_values(f.x, FIRST, SECOND, THIRD, FOURTH)
See Also
- For additional information on the scl_values pragma, including constraints, refer to the section on scl_values in the SCL Reference Guide.