gpt4 book ai didi

c - 为什么这句话消除了 "unreferenced function argument warning"?

转载 作者:行者123 更新时间:2023-11-30 19:38:39 25 4
gpt4 key购买 nike

在 SDCC 编译器用户指南中,我阅读了以下内容:

void to_buffer( unsigned char c )
{
c; // to avoid warning: unreferenced function argument
__asm
; save used registers here.
; If we were still using r2,r3 we would have to push them here.
; if( head != (unsigned char)(tail-1) )
mov a,_tail
dec a
xrl a,_head
; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
jz t_b_end$
;
; buf[ head++ ] = c;
mov a,dpl ; dpl holds lower byte of function argument
mov dpl,_head ; buf is 0x100 byte aligned so head can be used directly
mov dph,#(_buf>>8)
movx @dptr,a
inc _head
; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
t_b_end$:
; restore used registers here
__endasm;
}

我不明白这句话"c; // to avoid warning: unreferenced function argument"是什么意思意思是,这是SDCC的特殊用法吗?还是C语言的特殊用法?

最佳答案

如果您有不使用的传入函数参数,编译器往往会警告您。在您的情况下,c; 是一个void 操作,用于访问变量并避免警告。类似于

 int func(char c)
{
(void)c;
//c is never used in the function
}

FWIW,在gcc中,要启用警告,使用-Wunused-parameter选项。 (-Wextra 中启用)

关于c - 为什么这句话消除了 "unreferenced function argument warning"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37708959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com