bendera opsi gcc -D

gcc -D mendefinisikan makro yang akan digunakan oleh preprocessor.

Sintaksis

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

Contoh

Tulis file sumber myfile.c :

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

 

Bangun myfile.c dan jalankan dengan DEBUG yang ditentukan:

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

 

Atau bangun myfile.c dan jalankan tanpa DEBUG ditentukan:

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

 


Lihat juga

Advertising

GCC
°• CmtoInchesConvert.com •°