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) > Type definition mapping for C (C code)
  
Type definition mapping for C (C code)
The Construction property of a Type Definition determines whether a Type Definition is an Array, Enumeration, Sequence or Alias:
For an Alias Type Definition, ACS generates an alias of its data type.
Example code:
/* This is an alias */
typedef int MyInt;
For an Array Type Definition, ACS generates an array of its data type. The upper and lower bounds properties determine the size of a one dimensional array.
Example code:
typedef int IntArray[10];
Reverser Notes: When reverse engineering one dimensional arrays, the Lower and Upper Bounds properties record the size of the array. When reverse engineering multi dimensional arrays the size of the array is recorded through the C Array Spec tag definition
For an Enumeration Type Definition, ACS generates an enumeration. The enumeration literals are used as the contents of the generated enumeration.
Example code:
enum Colors{Colors_red, Colors_green, Colors_blue};
* 
When a Type Definition is of Enumeration construction, you can apply the «C Enumeration» stereotype and mark the Type Definition as anonymous through the C Anonymous Item tag definition.
For a Sequence Type Definition, ACS generates an array of its data type. The minimum and maximum size properties determine the size of the array.
Example code:
typedef int IntArray[10];
Reverser Notes: When reverse engineering an array, the Reverser creates a Type Definition of Array construction, even if the array was generated from a Type Definition of Sequence construction
ACS generates a Type Definition globally or within a struct definition:
Globally if the Model or a Package owns the Type Definition.
Within a struct definition if a Class or Signal owns the Type Definition.
The typedef declaration is derived from the properties of the Type Definition and the tagged values set for Tag Definitions that are applied by the «C Typedef» and «C Enumeration» stereotypes. Except for the C Anonymous Item tag definition, the listed tag definitions are applied by the «C Typedef» stereotype.
Child items:
If the Type Definition owns Enumeration Literals (Type Definitions of Enumeration construction only), each Enumeration Literal is generated inside the enumeration declaration. By default, the name of each generated enumeration literal is prefixed with the name of its typedef followed by an underscore. For Enumeration Literal mapping information, see Enumeration literal mapping for C (C code) .
Example code:
enum Colors{Colors_red, Colors_green, Colors_blue};
Properties:
For information about the Construction property, see the opening text of this topic.
If the Data Type property is set, ACS generates the value as the typedef's data type, unless there is a value set for the C Function Pointer Return tag definition, in which case that value is used for the typedef's data type.
Example code:
typedef float MyFloat;
Reverser Notes: When reverse engineering a typedef's data type:
If the data type is modeled in the Model or is going to be reverse engineered to the Model, the Type Definition's Data Type references the appropriate item.
If the data type is not modeled in the Model and is not going to be reverse engineered to the Model, the Type Definition's Data Type is set to the name of the data type (as text).
If the data type is a function pointer, the Type Definition's Data Type is not set and instead the C Function Pointer Return and C Function Pointer Parameter tag definitions are used to record the data type.
If no data type is specified, ACS generates int by default. If you want ACS to generate a different default in the absence of a data type for an Attribute, Parameter or Type Definition, change the default value that is specified in the C_Sync.ini file. Tell me more...
If the Description property has a value, ACS generates the description as a comment on the line before the typedef. .
Example code:
/* Comment for typedef foo */
typedef int foo;
Reverser Notes: When reverse engineering comments, both preceding and inline comments are reverse engineered to the Description property. Tell me more...
The Lower Bound and Upper Bound properties (Type Definitions of Array construction only) are used to calculate the array dimension, unless a value is set for the C Array Spec tag definition. If the tagged value of the C Array Spec tag definition has been set, the value is used to generate the array dimension and the Lower Bound and Upper Bound properties are ignored. .
Example code:
typedef int IntArray [10];
Array dimension = Upper Bound value - Lower Bound value + 1
Reverser Notes: When reverse engineering one dimensional arrays, the Reverser records the array dimension through the Lower Bound and Upper Bound properties. When reverse engineering multi dimensional arrays, the Reverser records the array dimension through the C Array Spec tag definition.
The Minimum Size property (Type Definitions of Sequence construction only) is ignored.
The Maximum Size property (Type Definitions of Sequence construction only) is used to calculate the array dimension, unless a value is set for the C Array Spec tag definition. If the tagged value of the C Array Spec tag definition has been set, the value is used to generate the array dimension and the Maximum Size property is ignored.
Example code:
typedef int IntArray [10];
Reverser Notes: When reverse engineering arrays, the Reverser reverse engineers a Type Definition of Array construction, rather than a Type Definition of Sequence construction:
The Name property is generated as the name of the typedef in the code.
Example code:
typedef float MyFloat;
* 
ACS may modify the typedef name that is added to the code to make it valid for C. You can specify the exact typedef name to add to the code through the CODE_GENERATION_NAME property of a Parameter. Tell me more...
If the Pointer property is set, an asterisk is generated after the data type. If a value is set for the C Indirection tag definition, the Pointer property is ignored.
Example code:
typedef int* NewIntPtr;
Reverser Notes: When reverse engineering a typedef that has any indirection, the Pointer property is set to TRUE and the indirection information is recorded through the C Indirection tag definition
If the Visibility property of a Type Definition is set to Public or Protected, the typedef is declared in the header file generated for the owning Class, Signal, Model or Package. If the Visibility property of a Type Definition is set to Private, the typedef is declared in the implementation file generated for the owning Class, Signal, Model or Package.
Tag Definitions:
The following tag definitions are applied to a Type Definition by the «C Enumeration» and «C Typedef» stereotypes:
The C Anonymous Item tag definition is applied by the «C Enumeration» stereotype and applies only to Type Definitions of Enumeration construction. If the tagged value of the C Anonymous Item tag definition is set to TRUE, it means that the enumeration is used as an anonymous type and is generated inline. ACS generates the anonymous enumeration inline.
Example code:
// A typedef called Colors whose underlying type is an anonymous enum.
// The enum would get reversed as something like unnamed0. We would never generate
// the enum on its own, only as part of another declaration.
typedef enum{red, green, blue} Colors;
Reverser Notes: When reverse engineering an enumeration that is used as an anonymous type, the Reverser creates a Type Definition in Modeler and sets its C Anonymous Item tag definition to TRUE. The name of the Type Definition is as follows:
unnamed<integer to make unique>
If the tagged value of the C Array Spec tag definition has been set, the value is used as the array specification. When the C Array Spec tag definition has been set, Lower Bound, Upper Bound and Maximum Size property values are ignored.
Example code:
typdef char String[255];
Reverser Notes: When reverse engineering multi-dimensional arrays, this tag definition records the array (including the square brackets). 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 data type.
Example code:
typedef const int NewCInt;
If the tagged value of the C Indirectiontag definition has been set, the value is used as the indirection, that is, the value is generated after the data type and before the typedef name.
Example code:
typedef int* NewCVInt;
If the tagged values of the C Function Pointer Parameters and C Function Pointer Return tag definitions have been set, other Type Definition properties are ignored. The Type Definition declaration is generated as follows:
Example code:
/* bool is the C Function Pointer Return value
int and char (*) (double) are C Function Pointer Parameter values */
typedef bool (*Fct2)(int, char (*) (double));
typedef <C Function Pointer Return> (<C Indirection><C Name>)(<C Function Pointer Parameters>);