我在 Ubuntu 18.04.3 LTS 中使用 gcc 版本编译器。使用 ROS 库。
我的代码非常简单:
typedef unsigned char boolean;
#define TRUE (boolean)(1)
#define FALSE (boolean)(0)
通过上面的编译,我得到了编译器错误:error: missing binary operator before token "("
#define TRUE (boolean)(1)
^
上面的用法#define
我猜是在操作系统库文件中。../../../M3N_BSW/bsw_pc/virtual/ros/librosc/XmlRpc/include/ros_lm_xml_value.h:80:6: note: in expansion of macro ‘TRUE’
---------------------------------------------------------------------
#if (TRUE == ROS_LM_XML_VALUE_DOUBLE_ENABLE) /* [05] */
^~~~
但是,当我定义如下时,没有错误。#define SOMETHING ( ( uchar8 ) 1 )
同样,关键字 boolean
在其他地方用于声明变量并且工作正常。引用下面的代码..和
使用地点是这样的:
#define ROS_LM_XML_VALUE_DOUBLE_ENABLE (FALSE)
someFunc()
{
boolean someVar=FALSE; //How come this is recognized correctly ?
#if (TRUE == ROS_LM_XML_VALUE_DOUBLE_ENABLE)
{
//Do something
}
}
关键字的使用 boolean
与 #define
某处出错。请指导我。
INTEGRITY
中使用了相同的代码操作系统。没有编译器错误。
最佳答案
似乎我们不能这样比较,因为 LHS 中的 TRUE 是类型转换的。这部分有问题。
#if (TRUE == ROS_LM_XML_VALUE_DOUBLE_ENABLE)
感谢您的支持。
关于ubuntu - C中 token "("之前缺少二元运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63126251/