indicador d'opció gcc -D

gcc -D defineix una macro que ha d'utilitzar el preprocessador.

Sintaxi

$ gcc -Dname [options] [source files] [-o output file]
$ gcc -Dname=definition [options] [source files] [-o output file]

Exemple

Escriu el fitxer font myfile.c :

// myfile.c
#include <stdio.h>
 
void main()
{
    #ifdef DEBUG   
       printf("Debug run\n");
    #else
       printf("Release run\n");
    #endif
}

 

Creeu myfile.c i executeu-lo amb DEBUG definit:

$ gcc -D DEBUG myfile.c -o myfile
$ ./myfile
Debug run
$

 

O construïu myfile.c i executeu-lo sense DEBUG definit:

$ gcc myfile.c -o myfile
$ ./myfile
Release run
$

 


Vegeu també

Advertising

GCC
°• CmtoInchesConvert.com •°