Studio:Scl struct sized: Difference between revisions
Line 41: | Line 41: | ||
<source lang=c> | <source lang=c> | ||
typedef struct { | typedef struct { | ||
int | int size; | ||
int | int someJunk; | ||
int | int moreJunk; | ||
} SimpleSizedStruct; | } SimpleSizedStruct; | ||
extern void f(SimpleSizedStruct* s); | extern void f(SimpleSizedStruct* s); | ||
#pragma scl_function(f) | #pragma scl_function(f) | ||
#pragma scl_struct_sized(f.s, | #pragma scl_struct_sized(f.s, size); | ||
</source> | </source> |
Revision as of 18:21, 5 November 2008
The scl_struct_sized pragma
The scl_struct_sized pragma is used to identify a sized structure. A sized structure is a C programming pattern representing structure whose size is variable and defined by one of the members of the structure. In other words the actual size of the structure is defined by programmer convention. This pragma is infrequently used, but must be used, whenever the programmer defined size does not match the C language size (as calculated by the sizeof macro) of the structure.
STRIDE Version Support
Available in STRIDE 3.0.0103 (StoneSteps Tower 3) and later versions
Syntax
#pragma scl_struct_sized(type-name, max-size)
Parameters | Type | Description |
type-name | Struct, Pointer |
Specifies a structure type (or a pointer to such type) that is to be sized (allocated bytes beyond its type definition).
The following restrictions apply:
|
max-size | Integer | Specifies the number of bytes to be allocated for the sized struct.
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* s);
#pragma scl_function(f)
#pragma scl_struct_sized(f.s, size);
Example 2
This example shows the declaration of a sized struct with a conformant array.
#define SOME_BOUND 1
typedef struct {
int nSize;
int nSomeJunk;
int ary[SOME_BOUND];
} ConformantArraySizedStruct;
extern void f(SimpleSizedStruct* s);
#pragma scl_function(f)
#pragma scl_struct_sized(f.s, nSize);
See Also
- For additional information on scl_string, including constraints, refer to the section on scl_struct_sized in the SCL Reference Guide.