gccコンパイルして、パラメータをプログラムに渡します

gccをコンパイルするときに-Dパラメーターを使用して、パラメーターをプログラムに渡します。

  1. gcc -DDEBUG -Dの直後にmacroコマンドが続きます。これは、このマクロを定義するのと同じです。このマクロのデフォルトの内容は1です。
  2. gcc -DNAME = Peter-Dの後にkey = valueが続くということは、キーのマクロを定義することを意味し、その内容はvalueです。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/un.h>


int main()
{
    
    
	printf("%d\n", DEBUG); //DEBUG为编译传入的参数
	return 0;
}

以下は、DEBUGパラメーターが2に等しく、デフォルト値が使用されている場合の出力結果です。
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/chengcheng1024/article/details/112321852