Studio:Scl string: Difference between revisions
Jump to navigation
Jump to search
(New page: = 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...) |
|||
(11 intermediate revisions by 4 users not shown) | |||
Line 5: | Line 5: | ||
== Syntax == | == Syntax == | ||
#pragma scl_string(type-name, max-size) | #pragma scl_string(type-name, max-size) | ||
#pragma scl_string(type-name, field-name, max-size) | #pragma scl_string(type-name, field-name, max-size) | ||
Line 18: | Line 18: | ||
* structure or union<br> | * structure or union<br> | ||
* the array/pointer type itself<br> | * the array/pointer type itself<br> | ||
* function name<br>If the container type is a structure or union and the array/pointer is a member, then field-name must be specified. | * function name<br> | ||
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]'' | | ''field-name [Optional]'' | ||
Line 30: | Line 31: | ||
|} | |} | ||
== | == Examples == | ||
1. Use the scl_string pragma to specify type definitions as null terminated ASCII strings. | |||
<source lang="c"> | |||
#define MAX_STR_SIZE 100 | |||
typedef char ArrayAsAsciiString_t[MAX_STR_SIZE]; | |||
#pragma scl_string( ArrayAsAsciiString_t, MAX_STR_SIZE ) | |||
= | typedef char* PointerAsAsciiString_t; | ||
#pragma scl_string( PointerAsAsciiString_t, MAX_STR_SIZE ) | |||
typedef struct { | |||
char * pointerToAsciiString; | |||
char arrayAsAsciiString[MAX_STR_SIZE]; | |||
} Struct_t; | |||
#pragma scl_string( Struct_t, pointerToAsciiString, MAX_STR_SIZE ) | |||
#pragma scl_string( Struct_t, arrayAsAsciiString, MAX_STR_SIZE ) | |||
</source> | |||
2. Use the scl_string pragma to specify a function argument as null terminated ASCII string. | |||
<source lang="c"> | |||
void SetString(const char* pBuf); | |||
#pragma scl_function(SetString) | |||
#pragma scl_string(SetString.pBuf, MAX_STR_SIZE) | |||
typedef struct { | |||
# | char * pBuf; | ||
# | } Struct_t; | ||
void SetSructString(Struct_t tValue); | |||
#pragma scl_function(SetSructString) | |||
#pragma scl_string(SetSructString.tValue.pBuf, MAX_STR_SIZE) | |||
</source> | |||
= | 3. Use the scl_string pragma to specify a function return value as null terminated ASCII string. | ||
<source lang="c"> | |||
const char* GetString(void); | |||
#pragma scl_function(GetString) | |||
#pragma scl_string(GetString(), MAX_STR_SIZE) | |||
typedef struct { | |||
char * pBuf; | |||
} Struct_t; | |||
Struct_t* GetSructString(void); | |||
#pragma scl_function(GetSructString) | |||
#pragma scl_string(GetSructString()->pBuf, MAX_STR_SIZE) | |||
</source> | |||
== | == See Also == | ||
* For additional information on scl_string, including constraints, refer to the section on scl_string in the [[Media:s2sSCLReferenceGuide.pdf|SCL Reference Guide]]. | |||
[[Category:Studio:SCL]] | |||
Latest revision as of 21:16, 29 June 2010
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:
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
1. Use the scl_string pragma to specify type definitions as null terminated ASCII strings.
#define MAX_STR_SIZE 100
typedef char ArrayAsAsciiString_t[MAX_STR_SIZE];
#pragma scl_string( ArrayAsAsciiString_t, MAX_STR_SIZE )
typedef char* PointerAsAsciiString_t;
#pragma scl_string( PointerAsAsciiString_t, MAX_STR_SIZE )
typedef struct {
char * pointerToAsciiString;
char arrayAsAsciiString[MAX_STR_SIZE];
} Struct_t;
#pragma scl_string( Struct_t, pointerToAsciiString, MAX_STR_SIZE )
#pragma scl_string( Struct_t, arrayAsAsciiString, MAX_STR_SIZE )
2. Use the scl_string pragma to specify a function argument as null terminated ASCII string.
void SetString(const char* pBuf);
#pragma scl_function(SetString)
#pragma scl_string(SetString.pBuf, MAX_STR_SIZE)
typedef struct {
char * pBuf;
} Struct_t;
void SetSructString(Struct_t tValue);
#pragma scl_function(SetSructString)
#pragma scl_string(SetSructString.tValue.pBuf, MAX_STR_SIZE)
3. Use the scl_string pragma to specify a function return value as null terminated ASCII string.
const char* GetString(void);
#pragma scl_function(GetString)
#pragma scl_string(GetString(), MAX_STR_SIZE)
typedef struct {
char * pBuf;
} Struct_t;
Struct_t* GetSructString(void);
#pragma scl_function(GetSructString)
#pragma scl_string(GetSructString()->pBuf, 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.