Difference between revisions of "Studio:Scl struct sized"

From STRIDE Wiki
Jump to: navigation, search
(Syntax)
(Syntax)
Line 15: Line 15:
 
| ''type-name''
 
| ''type-name''
 
| Struct,<br>Pointer
 
| Struct,<br>Pointer
| Specifies a structure type (or a pointer to such type) that is to be sized (allocated bytes beyond its type definition).
+
| Identifies a structure type or structure instance whose runtime size is not the same as it C language size and contains a field whose value is the runtime size.
 
The following restrictions apply:
 
The following restrictions apply:
 
* The structure type may not be pointed to by a sized pointer.
 
* The structure type may not be pointed to by a sized pointer.
 
* The structure type may not be a member of any other structure or union.
 
* The structure type may not be a member of any other structure or union.
* The structure type may not be passed as a function parameter.
+
* The structure type may not be passed as a function parameter (but a pointer to it is allowed).
* The structure type may only reside in IN/INOUT memory blocks.
+
* The structure type may reside only within IN or INOUT memory blocks.
 
* If the last member of the structure is an array, the array's size is calculated based upon max-size - (size of struct's other members).
 
* If the last member of the structure is an array, the array's size is calculated based upon max-size - (size of struct's other members).
 
* If the last member of the structure is an array, the array's element type may not contain a sized structure or a conformant array (see [[scl_conform]]).
 
* If the last member of the structure is an array, the array's element type may not contain a sized structure or a conformant array (see [[scl_conform]]).

Revision as of 12:32, 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, size-field)

Parameters Type Description
type-name Struct,
Pointer
Identifies a structure type or structure instance whose runtime size is not the same as it C language size and contains a field whose value is the runtime size.

The following restrictions apply:

  • The structure type may not be pointed to by a sized pointer.
  • The structure type may not be a member of any other structure or union.
  • The structure type may not be passed as a function parameter (but a pointer to it is allowed).
  • The structure type may reside only within IN or INOUT memory blocks.
  • If the last member of the structure is an array, the array's size is calculated based upon max-size - (size of struct's other members).
  • If the last member of the structure is an array, the array's element type may not contain a sized structure or a conformant array (see scl_conform).
size-field Integer Specifies the number of bytes to be allocated for the sized struct.

The following restrictions apply:

  • The type of the size-field must be an integral type (int, short, char).
  • The value (at runtime) is expected to be greater than the structure type size.
  • The size-field must be in the same payload block as the type-name sized struct.

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);
#pragma scl_function(f)
#pragma scl_struct_sized(*f.ps, size);

Example 2

This example shows the declaration of a sized struct with a conformant array.

#define SOME_BOUND 1
typedef struct {
    int size;
    int someJunk;
    int ary[SOME_BOUND];
} ConformantArraySizedStruct;

extern void f(SimpleSizedStruct* ps);
#pragma scl_function(f)
#pragma scl_struct_sized(*f.ps, size);

See Also

  • For additional information on scl_string, including constraints, refer to the section on scl_struct_sized in the SCL Reference Guide.