什么是 ISO C++禁止指针和整数之间的比较?
Serial.print("ugm3 = " );
Serial.print(ugm3);
Serial.println("ug/m3" );
lowpulseoccupancy = 0;
starttime = millis();
if (Serial.available())
{
char output = Serial.read();
if(output < "ugm3 = 80ug/m3")
{
for(int i = 0; i<5; i++)
{
angle = angle +1;
if(angle >= 30)
angle = 30;
我写了这些代码 有编译错误
if(output < "ugm3 = 80ug/m3")
说 ISO C ++禁止指针和整数之间的比较 因此,我已经更改了一些更改,例如'ugm3 = 80ug/m3'或'80ug/m3'等。 但是发生同样的错误 该错误是什么意思?
Serial.print("ugm3 = " );
Serial.print(ugm3);
Serial.println("ug/m3" );
lowpulseoccupancy = 0;
starttime = millis();
if (Serial.available())
{
char output = Serial.read();
if(output < "ugm3 = 80ug/m3")
{
for(int i = 0; i<5; i++)
{
angle = angle +1;
if(angle >= 30)
angle = 30;
I wrote these code
there is compiling error at
if(output < "ugm3 = 80ug/m3")
it says
ISO C++ forbids comparison between pointer and integer
so, I've already changed some times such as 'ugm3 = 80ug/m3' or '80ug/m3' etc.
but the same error occurs
what does that error mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
output
变量是一个(单个)char
,当用作<
(或几乎任何其他运算符)的操作数时,它会被转换(或“升级”)为int
。但是,您的"ugm3 = 80ug/m3"
是一个 字符串文字,它被解释为指向字符串第一个元素的指针。正如编译器给出的错误消息(非常清楚地)指出的那样,C++ 中禁止进行整型和指针类型之间的比较。
Your
output
variable is a (single)char
which, when used as the operand of<
(or almost any other operator), is converted (or 'promoted') to anint
. However, your"ugm3 = 80ug/m3"
is a string literal, which is interpreted as a pointer to the first element of the string.Comparisons between integral types and pointer types are forbidden in C++, as indicated (quite clearly) by the error message your compiler gives you.