-qinitauto

Category

Error checking and debugging

Pragma equivalent

#pragma options [no]initauto

Purpose

Initializes uninitialized automatic variables to a specific value, for debugging purposes.

Syntax

Read syntax diagramSkip visual syntax diagram
        .-noinitauto-------------.   
>>- -q--+-initauto--=--hex_value-+-----------------------------><

Defaults

-qnoinitauto

Parameters

hex_value
A one- to eight-digit hexadecimal number.

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