-D

Category

Language element control

Pragma equivalent

None.

Purpose

Defines a macro as in a #define preprocessor directive.

Syntax

Read syntax diagramSkip visual syntax diagram
>>- -D--name--+---------------+--------------------------------><
              '-=--definition-'   

Defaults

Not applicable.

Parameters

name
The macro you want to define. -Dname is equivalent to #define name. For example, -DCOUNT is equivalent to #define COUNT.
definition
The value to be assigned to name. -Dname=definition is equivalent to #define name definition. For example, -DCOUNT=100 is equivalent to #define COUNT 100.

Usage

Using the #define directive to define a macro name already defined by the -D option will result in an error condition.

To aid in program portability and standards compliance, the operating system provides several header files that refer to macro names you can set with the -D option. You can find most of these header files either in the /usr/include directory or in the /usr/include/sys directory. To ensure that the correct macros for your source file are defined, use the -D option with the appropriate macro name. For example, if your source file includes the /usr/include/sys/stat.h header file, you must compile with the option -D_POSIX_SOURCE to pick up the correct definitions for that file.

The -Uname option, which is used to undefine macros defined by the -D option, has a higher precedence than the -Dname option.

Predefined macros

The compiler configuration file uses the -D option to predefine several macro names for specific invocation commands. For details, see the configuration file for your system.

Examples

AIX® 4.2 and later provides support for files greater than 2 gigabytes in size so you can store large quantities of data in a single file. To allow large file manipulation in your application, compile with the -D_LARGE_FILES and -qlonglong compiler options. For example:
xlc myprogram.c -D_LARGE_FILES -qlonglong
To specify that all instances of the name COUNT be replaced by 100 in myprogram.c, enter:
xlc myprogram.c -DCOUNT=100

Related information