c - 为 MicroChip 编译时出错 'invalid operands to binary =='

标签 c struct

static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt,coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{

 if (inpkt->payload.len == 0)
    return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, COAP_RSPCODE_BAD_REQUEST, COAP_CONTENTTYPE_TEXT_PLAIN);

 if (inpkt->payload.p[0] == '1')
 {
    light = '1';


    UARTWrite(1,"ON\n");


    return coap_make_response(scratch, outpkt, (const UINT8_VAL *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN);
 }
 else
 {
    light = '0';

    UARTWrite(1,"OFF\n");

    return coap_make_response(scratch, outpkt, (const UINT8_VAL *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN);
 }
}

这是我的代码,我在第 5 行遇到错误。该结构定义为

typedef struct
{
    coap_header_t hdr;
    coap_buffer_t tok;
    uint8_t numopts;
    coap_option_t opts[MAXOPT];
    coap_buffer_t payload;
} coap_packet_t;

    typedef struct
{
    const UINT8_VAL *p;
    size_t len;
} coap_buffer_t;

当我尝试使用主要是 C 编译器的 Microchip c30 编译器进行编译时,出现以下错误。

Error :- error: invalid operands to binary ==

请帮帮我!!

最佳答案

尝试使用 UINT8_VAL 的 Val 成员进行比较:

inpkt->payloadp[0].Val == '1' 

关于c - 为 MicroChip 编译时出错 'invalid operands to binary ==',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23934470/

相关文章:

c++ - 编写内联函数(非内联函数)C/C++

C - 将 "composited/inherited"结构实例传递给其基本类型的指针

c++ - 删除 C 结构结尾填充的最佳做法是什么?

c - 害怕只从我第一次运行程序时开始阅读

c - 如何在 C 中用 8 位表示二进制数据

编译pyx文件

c - 从 C 语言文件中读取、处理和输出数字

c - 如何编译自定义PulseAudio模块?

c++ - C++结构位字段无法正确解析数据

c - 接收到结构数组