来吧! 看看C语言可以做什么骚操作

1. 交换操作

^

int main()
{
	int a = 500;
	int b = 1000;

	a = a ^ b;
	b = a ^ b;
	a = a ^ b;

    // after a = 1000, b = 500;
}

+ / -

int main()
{
	int a = 500;
	int b = 1000;

	a = a + b;
	b = a - b;
	a = a - b;

    // after a = 1000, b = 500;
}

ATTN: 站在效率的角度, 建议使用临时变量做中转.

2. 你没见过的 swtich()

#define A 1
#define B 2
#define C 3
#define D 4
#define J 10

int main()
{   
    int args = B;
    switch (args) {
    case A...C:
        // todo...
        break;
    case D:
        break;
    case J:
        break;
    default:
        break;
    }
    
    return 0;
}

3. 莫名其妙的 ’ : ’

typedef struct {
    int data:1;    // 位域变量
}BitType;

4. Define # / ##.

#define SNDRV_PCM_HW_PARAM_ACCESS 0  
#define SNDRV_PCM_HW_PARAM_FORMAT 1  
#define SNDRV_PCM_HW_PARAM_SUBFORMAT 2  
#define SNDRV_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_ACCESS
#define SNDRV_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_SUBFORMAT

#define SNDRV_PCM_HW_PARAM_SAMPLE_BITS 8  
#define SNDRV_PCM_HW_PARAM_FRAME_BITS 9  
#define SNDRV_PCM_HW_PARAM_CHANNELS 10  
#define SNDRV_PCM_HW_PARAM_RATE 11  
#define SNDRV_PCM_HW_PARAM_PERIOD_TIME 12  
#define SNDRV_PCM_HW_PARAM_PERIOD_SIZE 13  
#define SNDRV_PCM_HW_PARAM_PERIOD_BYTES 14  
#define SNDRV_PCM_HW_PARAM_PERIODS 15  
#define SNDRV_PCM_HW_PARAM_BUFFER_TIME 16  
#define SNDRV_PCM_HW_PARAM_BUFFER_SIZE 17  
#define SNDRV_PCM_HW_PARAM_BUFFER_BYTES 18  
#define SNDRV_PCM_HW_PARAM_TICK_TIME 19  
#define SNDRV_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_SAMPLE_BITS
#define SNDRV_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_TICK_TIME

#define HW_PARAM(v) [SNDRV_PCM_HW_PARAM_##v] = #v

static const char * const snd_pcm_hw_param_names[] = {
	HW_PARAM(ACCESS),
	HW_PARAM(FORMAT),
	HW_PARAM(SUBFORMAT),
	HW_PARAM(SAMPLE_BITS),
	HW_PARAM(FRAME_BITS),
	HW_PARAM(CHANNELS),
	HW_PARAM(RATE),
	HW_PARAM(PERIOD_TIME),
	HW_PARAM(PERIOD_SIZE),
	HW_PARAM(PERIOD_BYTES),
	HW_PARAM(PERIODS),
	HW_PARAM(BUFFER_TIME),
	HW_PARAM(BUFFER_SIZE),
	HW_PARAM(BUFFER_BYTES),
	HW_PARAM(TICK_TIME),
};

Tips: # ## 操作可以让代码变得简洁.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值