Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > C Code > Generating C Code > Overview of generating C code (C code) > Overview of modeling C code (C code) > Overview of modeling C code (C code) > Operation mapping for C (C code)
  
Operation mapping for C (C code)
ACS generates an Operation globally or within a struct definition:
Globally if the Model or a Package owns the Operation.
Example code:
// foo.h
void Operation1(void);
Within the file created for an owning Class, Data Type or Interface, but not within the struct definition
Example code:
// foo.h
struct foo
{
int Attribute1;
};
void Operation1(void);
If the Operation is owned by an Interface, ACS generates the Operation as a function pointer member.
The function declaration and implementation is derived from the properties of the Operation and the tagged values set for Tag Definitions that are applied by the «C Operation» stereotype.
Child items:
If the Operation owns Parameters, the parameters are generated in the order specified in Modeler. For Parameter mapping information, see .
Example code:
int sum(int first, int second)
{
return first +second;
}
Properties:
The Abstract property is ignored.
If the Visibility property is set to Public or Protected, the Operation is generated as a prototype in the header file with a full definition in the implementation file. If the Visibility property is set to Private, the function is defined in the implementation file and marked as static.
Example code:
inline int max_value (int a, int b)
{
if (a >= b)
return (a);
else
/* File foo.h */
struct foo
{
};
void op1(); /*public operation*/
void op2(); /*protected operation*/
/* File foo.c */
void op1() /*public operation*/
{
}
void op2() /*protected operation*/
{
}
static void op3() /*private operation*/
{
}
Reverser Notes: When reverse engineering a function:
If the function is marked as static, theVisibility property of the Operation is set to Private.
If the function is not marked as static, the Visibility property of the Operation is set to Public.
The Binding property is ignored.
Reverser Notes: When reverse engineering functions, the Reverser sets the Binding property to At Compile
If the Body property has a value, ACS may generate the value as the body of the associated function.
Whether ACS generates the Body property is determined by the ACS settings. For more information about maintaining operation bodies through ACS, see Strategy for maintaining reversible properties (ACS)
If you add an Event to an Operation Body as a model object reference, ACS can generates the Event as a notification call. Tell me more...
Reverser Notes: When reverse engineering, the Reverser updates the Operation Body property in Modeler as follows:
If the Reverse Engineer Code Bodies check box (Reverse Engineering Options 1 page) is cleared, the Reverser does not update the Operation Body property in the Model.
If the Reverse Engineer Code Bodies check box (Reverse Engineering Options 1 page) is selected, the Reverser updates the Operation Body property with the associated function body code. Note that blank function body code will result in the associated Operation's Body property being made blank.
TheReverser attempts to preserve model object references.
If the Data Usage property is set to On Instance, ACS generates a 'this' parameter.
Example code:
#include "Class1.h"
int Operation1(struct Class1* this, int Parameter1,
int Parameter2)
Reverser Notes: When reverse engineering 'this' parameters, the Reverser does not create a 'this' parameter in the Model.
If the Description property has a value, ACS generates the description as a comment on the line before the function.
Example code:
/* Comment for operation foo */
int foo();
The Immutable property is ignored.
The Name property is generated as the name of the function in the code.
Example code:
int foo();
* 
ACS may modify the function name that is added to the code to make it valid for C. You can specify the exact function name to add to the code through the CODE_GENERATION_NAME property of an Operation. Tell me more...
If the Return Type property is set, ACS generates the value as the function's return type, unless there is a value set for the C Function Pointer Return tag definition, in which case that value is used for the function's return type.
Example code:
float getPI()
{
return 3.14;
}
If no return type is specified, ACS generates void by default. If you want ACS to generate a different default in the absence of a return type, change the default value that is specified in the C_Sync.ini file. Tell me more...
Reverser Notes: When reverse engineering an function's return type:
If the return type is modeled in the Model or is going to be reverse engineered to the Model, the Operation's Return Type references the appropriate item.
If the return type is not modeled in the Model and is not going to be reverse engineered to the Model, the Operation's Return Type is set to the name of the return type as text.
If the return type is a function pointer, the Operation's Return Type is not set and instead the C Function Pointer Return and C Function Pointer Parameter tag definitions are used to record the return type.
The Timing properties (Synchronization and Duration) are ignored.
Tag Definitions:
When the «CMacro» stereotype is applied to an Operation, ACS generates the Operation as a function macro:
#define <operation name> (<comma separated list of parameters>) <operation body code>
The following tag definitions are applied to an Operation by the «C Operation» stereotype:
If the tagged value of the C CV Qualifier tag definition is set to const, volatile or const volatile, the selected keyword is generated before the return type.
Example code:
const int op1();
volatile float op2();
const volatile char op3
{ return 'z';}
If the tagged values of the C Function Pointer Parameters and C Function Pointer Return tag definitions have been set, the Operation is generated as follows:
Example code:
/* bool * is the C Function Pointer Return value shown in red
int and char (*) (double) are C Function Pointer Parameters */
bool* (* signal2(int, void (*)(int)))(int, char (*) (double))
{
return 0;
}
Function Declaration:
<C Function Pointer Return>(<C Indirection><derived C Name>(<Parameters>))(<C Function Pointer Parameters>);
Function Implementation:
<C Function Pointer Return>(<C Indirection><derived C Name>(<Parameters>))(<C Function Pointer Parameters>);
Reverser Notes: When reverse engineering functions that are of type function pointer, the C Function Pointer Return and C Function Pointer Parameters tag definitions are used to record the function pointer and parameters
If the tagged value of the C Indirection tag definition has been set, the value is used as an indirection, that is, the value is generated after the return type and before the function name.
Example code:
const int* foo();
volatile float* const pi();
const volatile char* const * foobar();
Reverser Notes: When reverse engineering functions that have indirection, all indirection is captured in the C Indirection tag definition.
If the tagged value of the C Inline tag definition is set to TRUE, the inline keyword is used.
Example code:
inline int max_value (int a, int b)
{
if (a >= b)
return (a);
else
return (b);
If the tagged value of the C Operation Implementation Comment tag definition has been set, the value is generated as a comment preceding the function implementation in the implementation file.
Example code:
/* An implementation comment for bar() */
void bar()
{
}
If the tagged value of the C Storage Classtag definition is set to static, auto, register or extern, the selected storage class keyword is generated. In the context of an Operation, only the static and extern values of the C Storage Class tag definition should be used.
Example code:
extern float getpi();