二进制的无效操作数==

时间:2013-02-15 09:36:35

标签: c

我有一个程序,我正在尝试编译,但它向我显示编译错误:     在第22行:“无效的操作数到二进制==” 我搜索了各种可用的解决方案,但找不到我的问题的解决方案。代码如下:

      #include <stdio.h>

        typedef struct nx_string_t
        {
            char *buf;  
        }nx_string_t;

        typedef struct nx_value_t
        {
            union
                {
                nx_string_t strng;
                }
        } nx_value_t;

        void func(nx_value_t *vale);

        void func(nx_value_t *vale)
        {
             if(vale->strng == NULL) // Error occurs here.
             {
                  printf("its done");    
             }
        }

2 个答案:

答案 0 :(得分:4)

成员strng的类型为nx_string_t,不是指针。

您必须与里面的指针元素进行比较:

if(value->strng.buf == NULL)

答案 1 :(得分:2)

比较应该是

if (vale->strng.buf == NULL)

vale->strng属于nx_string_t类型,它不是指针,因此永远不会是NULL。但它有一个buf指针成员,可以是NULL

相关问题