Difference between revisions of "Studio:Scl struct sized"

From STRIDE Wiki
Jump to: navigation, search
(Syntax)
(Syntax)
Line 12: Line 12:
 
|-
 
|-
 
| ''type-name''
 
| ''type-name''
| Struct or Struct*
+
| Struct<br>Struct*
 
| Specifies a structure type that is to be sized (allocated bytes beyond its type definition).
 
| Specifies a structure type that is to be sized (allocated bytes beyond its type definition).
 +
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.
Line 21: Line 22:
 
|-
 
|-
 
| ''max-size''
 
| ''max-size''
| Member Field of type-name
+
| Member Field of<br>type-name
| Specifies the number of bytes for the sized struct.
+
| Specifies the number of bytes to be allocated for the sized struct.
* The value contained by max_size may not be less than the structure's type size.
+
The following restrictions apply:
* The max-size value must be an integral type (int, short, char).
+
* The max-size type must be an integral type (int, short, char).
* The max-size may not exceed the maximum payload size.
+
* The max-size value (at runtime) may not be less than the structure's type size.
* The max_size must reside in the same payload block as the sized struct (no indirection '*' or '->').
+
* The max-size value (at runtime) may not exceed the maximum payload size.
 +
* The max_size field must be in the same payload block as the type-name sized struct (i.e. no indirection '*' or '->').
 
|}
 
|}
  

Revision as of 17:35, 31 October 2008

The scl_struct_sized pragma

The scl_struct_sized pragma identifies a particular struct or pointer-to-struct as a sized structure. A sized structure typically has bytes allocated past its type definition.

Syntax

#pragma scl_struct_sized(type-name, max-size)

Parameters Type Description
type-name Struct
Struct*
Specifies a structure type that is to be sized (allocated bytes beyond its type definition).

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.
  • The structure type may only reside in IN/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).
max-size Member Field of
type-name
Specifies the number of bytes to be allocated for the sized struct.

The following restrictions apply:

  • The max-size type must be an integral type (int, short, char).
  • The max-size value (at runtime) may not be less than the structure's type size.
  • The max-size value (at runtime) may not exceed the maximum payload size.
  • The max_size field must be in the same payload block as the type-name sized struct (i.e. no indirection '*' or '->').

Examples

Example 1

This example shows the declaration for a simple sized struct.

typedef struct {
    int nSize;
    int nSomeJunk;
    int nMoreJunk;
} SimpleSizedStruct;

extern void f(SimpleSizedStruct* s);
#pragma scl_struct_sized(f.s, nSize);

Example 2

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

#define SOME_BOUND 0
typedef struct {
    int nSize;
    int nSomeJunk;
    int ary[SOME_BOUND];
} ConformantArraySizedStruct;

extern void f(SimpleSizedStruct* s);
#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.