Pragma equivalent
#pragma options [no]initauto
Purpose
Initializes uninitialized automatic variables
to a specific value, for debugging purposes.
Syntax
.-noinitauto-------------.
>>- -q--+-initauto--=--hex_value-+-----------------------------><
Parameters
- hex_value
- A one- to eight-digit hexadecimal number.
- To initialize each byte of storage to a specific value, specify one or two
digits for the hex_value.
- To initialize each word of storage to a specific value, specify three to eight
digits for the hex_value.
- In the case where less than the maximum number of
digits are specified for the size of the initializer requested, leading
zeros are assumed.
- In the case of word initialization, if an automatic variable is
smaller than a multiple of 4 bytes in length, the hex_value is
truncated on the left to fit. For example, if an automatic variable
is only 1 byte and you specify five digits for the hex_value,
the compiler truncates the three digits on the left and assigns the
other two digits on the right to the variable. See Example 1.
- If an automatic variable is larger than the hex_value in
length, the compiler repeats the hex_value and
assigns it to the variable. See Example
1.
- If the automatic variable is an array, the hex_value is
copied into the memory location of the array in a repeating pattern,
beginning at the first memory location of the array. See Example 2.
- You can specify alphabetic digits as either uppercase or lowercase.
- The hex_value can be optionally
prefixed with 0x, in which x is
case-insensitive.
Usage
The -qinitauto option provides
the following benefits:
- Setting hex_value to zero
ensures that all non-variably modified automatic variables are cleared before being
used.
- You can use this option to initialize variables of real or complex
type to a signaling or quiet NaN, which helps locate uninitialized
variables in your program.
This option generates extra code to initialize the value
of automatic variables. It reduces the runtime performance of the
program and is to be used for debugging purposes only.
Restrictions: - Objects that are equivalenced, structure components, and array
elements are not initialized individually. Instead, the entire storage
sequence is initialized collectively.
- The -qinitauto=hex_value option
does not initialize variable length arrays.
Predefined macros
- __INITAUTO__ is defined to the hex_value that
is specified on the -qinitauto option or
pragma; otherwise, it is undefined.
- __INITAUTO_W__ is defined to the hex_value,
repeated four times, which are specified on the -qinitauto option
or pragma; otherwise, it is undefined.
Examples
Example 1: Use
the -qinitauto option to initialize automatic
variables of scalar types.
#include <stdio.h>
int main()
{
char a;
short b;
int c;
long long int d;
printf("char a = 0x%X\n",(char)a);
printf("short b = 0x%X\n",(short)b);
printf("int c = 0x%X\n",c);
printf("long long int d = 0x%llX\n",d);
}
If you compile the program with -qinitauto=AABBCCDD,
for example, the result is as follows:
char a = 0xDD
short b = 0xFFFFCCDD
int c = 0xAABBCCDD
long long int d = 0xAABBCCDDAABBCCDD
Example 2: Use
the -qinitauto option to initialize automatic
array variables.
#include <stdio.h>
#define ARRAY_SIZE 5
int main()
{
char a[5];
short b[5];
int c[5];
long long int d[5];
printf("array of char: ");
for (int i = 0; i<ARRAY_SIZE; i++)
printf("0x%1X ",(unsigned)a[i]);
printf("\n");
printf("array of short: ");
for (int i = 0; i<ARRAY_SIZE; i++)
printf("0x%1X ",(unsigned)b[i]);
printf("\n");
printf("array of int: ");
for (int i = 0; i<ARRAY_SIZE; i++)
printf("0x%1X ",(unsigned)c[i]);
printf("\n");
printf("array of long long int: ");
for (int i = 0; i<ARRAY_SIZE; i++)
printf("0x%1X ",(unsigned)d[i]);
printf("\n");
}
If you compile the program with -qinitauto=AABBCCDD,
for example, the result is as follows:
array of char: OxAA OxBB OxCC OxDD OxAA
array of short: OxAABB OxCCDD OxAABB OxCCDD OxAABB
array of int: OxAABBCCDD OxAABBCCDD OxAABBCCDD OxAABBCCDD OxAABBCCDD
array of long long int: 0xAABBCCDDAABBCCDD 0xAABBCCDDAABBCCDD 0xAABBCCDDAABBCCDD
0xAABBCCDDAABBCCDD 0xAABBCCDDAABBCCDD