Studio:Scl conform: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
(New page: = The scl_conform pragma= The scl_conform pragma allows the user to define a conformant array within a payload. The payload can be a C structure or a parameter declaration list. The confor...)
 
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= The scl_conform pragma=
= The scl_conform pragma =
The scl_conform pragma allows the user to define a conformant array within a payload. The payload can be a C structure or a parameter declaration list. The conformant array must be the last item in the payload (e.g., the last field in the structure, or the last parameter in the declaration list). Because of this, only the payload name and the name of the size field in that payload are required. The SCL compiler automatically assumes the conformant array field within the specified payload.  
The scl_conform pragma allows the user to define a conformant array within a payload. The payload can be a C structure or a parameter declaration list. The conformant array must be the last item in the payload (e.g., the last field in the structure, or the last parameter in the declaration list). Because of this, only the payload name and the name of the size field in that payload are required. The SCL compiler automatically assumes the conformant array field within the specified payload.  


'''Note:''' Because scl_conform is a rarely-used SCL pragma, you may find [[scl_ptr_sized]] to be more appropriate for your interface.
NOTE: ''For an alternative use case of sized structure please look at [[scl_struct_sized]] pragma.''


== Syntax ==
== Syntax ==
Line 15: Line 15:
| String
| String
| Name of the structure or function that encapsulates the conformant array
| Name of the structure or function that encapsulates the conformant array
The following restrictions apply:
* The structure type may not be pointed to by a sized pointer.
* The structure type may not be used in an array.
* The structure type may not be a member of an union.
* The structure type may not be a member of any other structure unless it is the last member.
* The structure type may not be passed as a formal parameter or return value of a function (but a pointer to it is allowed).
* The structure type cannot reside within OUT memory block.
|-  
|-  
| ''size-name''
| ''size-name''
| Member
| Member
| Name of the structure field or function parameter that contains the size of the array
| Name of the structure field or function parameter that contains the size of the array
The following restrictions apply:
* The type of the size-name must be an integral type.
* The size-field must reside within the same payload block as the structure or the function payload.
|-  
|-  
| ''max-size''
| ''max-size''
Line 24: Line 34:
| Maximum size of the conformant array
| Maximum size of the conformant array
|}
|}
== Notes ==
* This pragma can only be used after the payload structure has been defined.
* For additional information on scl_conform, including constraints, refer to the section on scl_conform in the [[http://www.s2technologies.com/pdf/s2sSCLReferenceGuide.pdf SCL Reference Guide]].


== Example ==
== Example ==
<source lang=c>
/* Constant defining the maximum array size */
#define MAX_BUFFER_SIZE 20


    /* Constant defining the maximum array size */
/* Structure defining a message payload with a conformant array */
    #define MAX_BUFFER_SIZE 20
/* The array field must be the last member in the payload      */
typedef struct {
  int f1;
  short bufferSize;
  char  buffer[1];
} CmdPayload_t;


    /* Structure defining a message payload with a conformant array */
/* Use the scl_conform pragma to define the conformant arrays */
#pragma scl_conform( CmdPayload_t, bufferSize, MAX_BUFFER_SIZE )
</source>


    /* The array field must be the last member in the payload      */
== See Also ==
    typedef struct {
* For additional information on scl_conform, including constraints, refer to the section on scl_conform in the [[Media:s2sSCLReferenceGuide.pdf|SCL Reference Guide]].
      int f1;
      short bufferSize;
      char  buffer[1];
    } CmdPayload_t;


    /* Use the scl_conform pragma to define the conformant arrays */
[[Category:Studio:SCL]]
    #pragma scl_conform( CmdPayload_t, bufferSize, MAX_BUFFER_SIZE )

Latest revision as of 20:35, 4 January 2012

The scl_conform pragma

The scl_conform pragma allows the user to define a conformant array within a payload. The payload can be a C structure or a parameter declaration list. The conformant array must be the last item in the payload (e.g., the last field in the structure, or the last parameter in the declaration list). Because of this, only the payload name and the name of the size field in that payload are required. The SCL compiler automatically assumes the conformant array field within the specified payload.

NOTE: For an alternative use case of sized structure please look at scl_struct_sized pragma.

Syntax

#pragma scl_conform(name, size-name, max-size)
Parameters Type Description
name String Name of the structure or function that encapsulates the conformant array

The following restrictions apply:

  • The structure type may not be pointed to by a sized pointer.
  • The structure type may not be used in an array.
  • The structure type may not be a member of an union.
  • The structure type may not be a member of any other structure unless it is the last member.
  • The structure type may not be passed as a formal parameter or return value of a function (but a pointer to it is allowed).
  • The structure type cannot reside within OUT memory block.
size-name Member Name of the structure field or function parameter that contains the size of the array

The following restrictions apply:

  • The type of the size-name must be an integral type.
  • The size-field must reside within the same payload block as the structure or the function payload.
max-size Integer Maximum size of the conformant array

Example

/* Constant defining the maximum array size */
#define MAX_BUFFER_SIZE 20

/* Structure defining a message payload with a conformant array */
/* The array field must be the last member in the payload       */
typedef struct {
  int f1;
  short bufferSize;
  char  buffer[1];
} CmdPayload_t;

/* Use the scl_conform pragma to define the conformant arrays */
#pragma scl_conform( CmdPayload_t, bufferSize, MAX_BUFFER_SIZE )

See Also

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