Studio:Scl ptr opaque

From STRIDE Wiki
Revision as of 18:23, 1 October 2008 by Ivailop (talk | contribs) (See Also)
Jump to: navigation, search

The scl_ptr_opaque pragma

The scl_ptr_opaque pragma is used to specify a pointer data type as pointing to opaque data that should not be marshaled.

Syntax

#pragma scl_ptr_opaque(type-name)

#pragma scl_ptr_opaque(type-name, field-name)
Parameters Type Description
type-name Type Name of the type that contains the Pointer. The container type may be the name of a structure, a union, the pointer type itself, or a function. If the container type is a structure or a union, then the pointer is a member and the field-name must be specified. If the container type is a function, then the pointer is a parameter and the field-name must be specified.
field-name [Optional] Member Name of the Pointer field, which may be a member field contained within a structure/union, or a parameter in the parameter list of a function.

Notes

  • An opaque pointer is a pointer that points to opaque data. This means that the receiver of the pointer may not examine the data being pointed to. The meaningful part of an opaque pointer is the pointer value itself, or the pointer address. Opaque pointer are often used for the passing of handles.
  • A pointer of type void (i.e., void *) is by default an opaque pointer. No pragma may be applied to a void pointer.

Examples

Two examples using the scl_ptr_opaque pragma are shown below:

Example 1

The first example uses the scl_ptr_opaque pragma to declare a structure member and a parameter list member as an opaque pointer.

// Typedef defining a structure with a member of type pointer to char //
typedef struct
{
  int f1;
  char * f2;
}data_t;

// Function prototype with an INOUT pointer of type data_t //
void modifyData( data_t * p );

// Use the scl_function pragma to associate a SUID with the function ModifyData //
#pragma scl_function( modifyData )
// Use the scl_ptr_opaque pragma to define the member f2 as opaque //
#pragma scl_ptr_opaque( data_t.f2 )
// Use the scl_ptr_opaque pragma to define the parameter p as opaque //
#pragma scl_ptr_opaque( modifyData.p )

Example 2

The second example uses the scl_ptr_opaque pragma to declare pointer type definitions as opaque.

// Typedef defining a structure with two members //
typedef struct
{
  int f1;
  char f2;
}data_t;

// Typedef defining a pointer to the data strucure //
typedef data_t * pointerToData;
// Prototype defining a function that returns a pointer to the data structure //
data_t * getData( void );

// Use the scl_ptr_opaque pragma to define the type pointerToData as opaque //
#pragma scl_ptr_opaque( pointerToData )
// Use the scl_function pragma to associate a SUID with the function "getData" //
#pragma scl_function( getData )
// Use the scl_ptr pragma to define "getData" return value as opaque pointer //
#pragma scl_ptr_opaque( getData )

See Also

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