As of ASN1C version 6.0, initialization functions are automatically generated (in previous versions, it was necessary to use the -genInit option to force this action). If for some reason, a user does want initialization functions to be generated, the -noInit switch can be used to turn initialization function generation off.
The use of initialization functions are optional - a variable can be initialized by simply setting its contents to zero (for example, by using the C run-time memset function). The advantage of initialization function is that they provide smarter initialization which can lead to improved application performance. For example, it is not necessary to set a large byte array to zero prior to its receiving a populated value. The use of memset in this situation can result in degraded performance.
Generated initialization functions are written to the main <module>.c file. This file contains common constants, global variables, and functions that are generic to all type of encode/decode functions. If the -cfile command-line option is used, the functions are written to the specified .c or .cpp file along with all other generated functions. If -maxcfiles is specified, each generated initialization function is written to a separate .c file.
The format of the name of each generated initialization function is as follows:
asn1Init_[<prefix>]<prodName>
where <prodName>
is the name of the ASN.1 production for which the
function is being generated and <prefix>
is an optional prefix that can be
set via a configuration file setting. The configuration setting used to set the prefix is
the <typePrefix> element. This element specifies a prefix that will be applied to all
generated typedef names and function names for the production.
The calling sequence for each generated initialization function is as follows:
asn1Init_<name> (<name>* pvalue)
In this definition, <name> denotes the prefixed production name defined above.
The pvalue argument is used to pass a pointer to a variable of the item to be initialized.