Studio:Scl string: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
No edit summary
Line 34: Line 34:


Two examples using the scl_string pragma are shown below:
Two examples using the scl_string pragma are shown below:
# The first example uses the scl_string pragma to define type definitions as null terminated ASCII strings.
# The second example uses the scl_string pragma to define a structure member and a parameter list member as null terminated ASCII strings.


=== Example 1 ===
=== Example 1 ===
The first example uses the scl_string pragma to define type definitions as null terminated ASCII strings.
<source lang=c>
#define MAX_STR_SIZE 100


    #define MAX_STR_SIZE 100
typedef char ArrayAsAsciiString_t[MAX_STR_SIZE];
typedef char* PointerAsAsciiString_t;
#pragma scl_string( PointerAsAsciiString_t, MAX_STR_SIZE )
#pragma scl_string( ArrayAsAsciiString_t, MAX_STR_SIZE )
   
   
    typedef char ArrayAsAsciiString_t[MAX_STR_SIZE];
void GetString(char* pBuf);
    typedef char* PointerAsAsciiString_t;
#pragma scl_function(GetString)
    #pragma scl_string( PointerAsAsciiString_t, MAX_STR_SIZE )
#pragma scl_ptr(GetString, pBuf, OUT, PRIVATE)
    #pragma scl_string( ArrayAsAsciiString_t, MAX_STR_SIZE )
#pragma scl_string(GetString, pBuf, MAX_STR_SIZE)
</source>
    void GetString(char* pBuf);
    #pragma scl_function(GetString)
    #pragma scl_ptr(GetString, pBuf, OUT, PRIVATE)
    #pragma scl_string(GetString, pBuf, MAX_STR_SIZE)


=== Example 2 ===
=== Example 2 ===
 
The second example uses the scl_string pragma to define a structure member and a parameter list member as null terminated ASCII strings.
    #define MAX_STR_SIZE 64   
<source lang=c>
#define MAX_STR_SIZE 64   
   
   
    /* ASCII string defined as a pointer to char */
/* ASCII string defined as a pointer to char */
    typedef struct {
typedef struct {
        char * pointerToAsciiString;
  char * pointerToAsciiString;
        char arrayAsAsciiString[MAX_STR_SIZE];
  char arrayAsAsciiString[MAX_STR_SIZE];
    }Struct_t;
} Struct_t;
   
   
    /* Function with an input parameter of type ASCII string */
/* Function with an input parameter of type ASCII string */
    void SetString( char * parameterAsAsciiString );
void SetString( char * parameterAsAsciiString );
    #pragma scl_function(SetString)
#pragma scl_function(SetString)
    /* Use the scl_string pragma to define the above structure    */
/* Use the scl_string pragma to define the above structure    */
    /* and parameter list members as null-terminated ASCII strings */
/* and parameter list members as null-terminated ASCII strings */
    #pragma scl_string( Struct_t, pointerToAsciiString, MAX_STR_SIZE )
#pragma scl_string( Struct_t, pointerToAsciiString, MAX_STR_SIZE )
    #pragma scl_string( Struct_t, arrayAsAsciiString, MAX_STR_SIZE )
#pragma scl_string( Struct_t, arrayAsAsciiString, MAX_STR_SIZE )
    #pragma scl_string( SetString, parameterAsAsciiString, MAX_STR_SIZE )
#pragma scl_string( SetString, parameterAsAsciiString, MAX_STR_SIZE )
</source>


== See Also ==
== See Also ==

Revision as of 00:27, 2 October 2008

The scl_string pragma

The scl_string pragma identifies a particular array type or pointer type as a string. The string type (ASCII or UNICODE) is derived from the element type (1-byte or 2-byte, respectively).

Syntax

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

#pragma scl_string(type-name, field-name, max-size)
Parameters Type Description
type-name Type Name of the type that contains the array/pointer:
  • structure or union
  • the array/pointer type itself
  • function name

If the container type is a structure or union and the array/pointer is a member, then field-name must be specified.

field-name [Optional] Member Optional name of the array/pointer member contained within a structure/union, or the name of the pointer in the parameter list of a function.

If type-name is a structure or union and the array/pointer is a member, then field-name must be specified.

max-size Integer Specifies the maximum length of the string.

Examples

Two examples using the scl_string pragma are shown below:

Example 1

The first example uses the scl_string pragma to define type definitions as null terminated ASCII strings.

#define MAX_STR_SIZE 100

typedef char ArrayAsAsciiString_t[MAX_STR_SIZE];
typedef char* PointerAsAsciiString_t; 
#pragma scl_string( PointerAsAsciiString_t, MAX_STR_SIZE )
#pragma scl_string( ArrayAsAsciiString_t, MAX_STR_SIZE )
 
void GetString(char* pBuf);
#pragma scl_function(GetString)
#pragma scl_ptr(GetString, pBuf, OUT, PRIVATE)
#pragma scl_string(GetString, pBuf, MAX_STR_SIZE)

Example 2

The second example uses the scl_string pragma to define a structure member and a parameter list member as null terminated ASCII strings.

#define MAX_STR_SIZE 64  
 
/* ASCII string defined as a pointer to char */
typedef struct {
  char * pointerToAsciiString;
  char arrayAsAsciiString[MAX_STR_SIZE];
} Struct_t;
 
/* Function with an input parameter of type ASCII string */
void SetString( char * parameterAsAsciiString );
#pragma scl_function(SetString)
/* Use the scl_string pragma to define the above structure     */
/* and parameter list members as null-terminated ASCII strings */
#pragma scl_string( Struct_t, pointerToAsciiString, MAX_STR_SIZE )
#pragma scl_string( Struct_t, arrayAsAsciiString, MAX_STR_SIZE )
#pragma scl_string( SetString, parameterAsAsciiString, MAX_STR_SIZE )

See Also

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