gpt4 book ai didi

c - 带函数返回的地址运算符 "&"

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:45 25 4
gpt4 key购买 nike

这个:

bit_is_set(optos(),opt)

扩展宏 bit_is_set:

((*(volatile uint8_t *)(((uint16_t) &(optos())))) & (1 << (opt)))

不工作,错误消息:左值需要作为一元“&”操作数。

但是这个:

uint8_t a=optos();
bit_is_set(a,opt)

工作正常。

为什么?

如何在函数返回时使用地址运算符“&”?

最佳答案

出于同样的原因,这将不起作用:

uint8_t optos() {
return 4;
}

int main(void) {
uint8_t* addr = &optos();
return 0;
}

error: lvalue required as unary ‘&’ operand

& 操作数需要一个左值来返回地址。临时右值(在您的例子中是从 optos() 返回的值)不能占用其地址,需要先绑定(bind)到左值。

关于c - 带函数返回的地址运算符 "&",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26721671/

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