#author("2019-07-11T11:25:08+08:00","default:Admin","Admin") C

用来把参数转换成字符串

#include <iostream>
 
#define LOG(x) do { printf("%s=%d\n",#x,x); }while(0)
 
int main()
{
    int score = 96;
    LOG(score);
    LOG(6);
    
    getchar();
    return 0;
}

输出:

score=96
6=6

##

用于将带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串;但它不可以是第一个或者最后一个子串。所谓的子串(token)就是指编译器能够识别的最小语法单元;

#include <iostream>
 
#define LOG(x) log##x()
 
void logA(){
    printf("log func A \n");
}
 
void logB(){
    printf("log func B\n");
}
 
int main()
{
    LOG(A);
 
    getchar();
    return 0;
}

输出:

log func A

__VA_ARGS__

用于在宏替换部分中,表示可变参数列表

#include <iostream>
 
#define LOG(...)  printf(__VA_ARGS__);
 
int main()
{
    LOG("score is %d\n",96);
 
    getchar();
    return 0;
}

输出:

score is 96

##__VA_ARGS__

和__VA_ARGS_作用类似

##__VA_ARGS__ 宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错



超多機能のアクセス解析が永久無料!

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:32:56 (1627d)

G|Cg|C@Amazon Yahoo yV

z[y[W yVoC[UNLIMITȂ1~] COiq COsیI