Studio:Scl struct sized: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
= The scl_struct_sized pragma = | |||
The scl_struct_sized pragma is used to identify a sized structure. A sized structure is a C programming convention for representing a structure whose size is variable and defined by one of the members of the structure. This pragma is infrequently used, but must be used, whenever the programmer defined size does not match the C language size of the structure (as calculated by the sizeof macro). | The scl_struct_sized pragma is used to identify a sized structure. A sized structure is a C programming convention for representing a structure whose size is variable and defined by one of the members of the structure. This pragma is infrequently used, but must be used, whenever the programmer defined size does not match the C language size of the structure (as calculated by the sizeof macro). |
Revision as of 00:11, 12 November 2011
The scl_struct_sized pragma
The scl_struct_sized pragma is used to identify a sized structure. A sized structure is a C programming convention for representing a structure whose size is variable and defined by one of the members of the structure. This pragma is infrequently used, but must be used, whenever the programmer defined size does not match the C language size of the structure (as calculated by the sizeof macro).
NOTE: For an alternative use case of sized structure please look at scl_conform pragma.
Syntax
#pragma scl_struct_sized(type-name, size-field)
Parameters | Type | Description |
type-name | Structure Type | Identifies a structure type or structure instance whose runtime size is not the same as its C language size and contains a field whose value is the runtime size.
The following restrictions apply:
|
size-field | Member | Identifies a field within the sized structure whose value determines the actual runtime size of the structure. The following restrictions apply:
|
Examples
Example 1
This example shows the declaration for a simple sized struct.
typedef struct {
int size;
int someJunk;
int moreJunk;
} SimpleSizedStruct;
extern void f(SimpleSizedStruct* ps);
#ifdef _SCL
#pragma scl_function(f)
#pragma scl_struct_sized(*f.ps, size);
#endif
Example 2
This example shows the declaration of a sized struct containing a variable length array whose actual length is proportional to the value of the size field. In this case the array bound is declared as 1, but by convention is really controlled by the value of the size field.
typedef struct {
int size;
int someJunk;
int ary[1]; // variable length array whose length depends on the size
} ConformantArraySizedStruct;
extern void f(ConformantArraySizedStruct* ps);
#ifdef _SCL
#pragma scl_function(f)
#pragma scl_struct_sized(*f.ps, size);
#endif
See Also
- For additional information on scl_struct_sized, including constraints, refer to the section on scl_struct_sized in the SCL Reference Guide.