c - 为什么 C 中的条件运算符在我的情况下不起作用?
问题描述
我有这段代码
int8_t startPage = ( ((uint8_t)(ceilf( (float)CurrentY / 8))) - 1);
/* variable = condition ? value_if_true : value_if_false*/
startPage<0 ? 0:startPage;
如果CurrentY
为 NULL,startPage
则为 -1。但是页面不能为负数。
所以我尝试检查它,如果 startPage 为负,则将其设置为 NULL。
但我有一个警告statement with no effect [-Wunused-value]
并且代码不起作用。有任何想法吗?
解决方案
startPage<0 ? 0:startPage;
未使用from 的值,因此编译器会警告您。
您可以执行以下操作:
startPage = (startPage < 0) ? 0 : startPage;
如果小于,则设置startPage
为。0
0
推荐阅读
- c - C数组在没有明显干预的情况下莫名其妙地改变了值
- r - 使用 R 的 bigrquery 库将数据追加/插入到 BigQuery 表中
- php - 我正在尝试在 PHP 中压缩一个数组
- python - Python Social Auth Django 安装失败
- javascript - firestore 针对 id 数组检查 id 是否存在
- arrays - 难以查询具有多个元素的嵌套数组 Mongoose
- go - 接受 *[128]uint8、*[256]uint8 等的函数
- javascript - 了解带有 es6 模块的基本 webpack
- amazon-web-services - 在 aws elastic beanstalk docker 部署期间出现“内存错误”
- apache - Apache 2.4 LogLevel 和重写被忽略