gpt4 book ai didi

c - 内联 if (? :) doesn't work in _delay_us()

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

当我试图在我的 1-Wire 实现中使用 _delay_us(condition ? value_if_true : value_if_false) 时,延迟不起作用,我的设备没有得到任何响应,但它工作正常当我将其替换为:

if(condition) _delay_us(value_if_true);
else _delay_us(value_if_false);

当我在 lcd 上显示内联 if 值时,它显示正确的值。

那么这两种表示法有什么区别呢?如果在 _delay_us() 中工作,我如何进行内联?

最佳答案

documentation明确地说:

In order for these functions to work as intended, compiler optimizations must be enabled, and the delay time must be an expression that is a known constant at compile-time. If these requirements are not met, the resulting delay will be much longer (and basically unpredictable), and applications that otherwise do not use floating-point calculations will experience severe code bloat by the floating-point library routines linked into the application.

关于c - 内联 if (? :) doesn't work in _delay_us(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9144461/

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