Abhishek
Abhishek

Reputation: 2034

invalid operands to binary ==

I have a program that I am trying to compile but it's showing me the compilation error : at line 22 : "invalid operands to binary ==" I searched through various available solutions but couldn't find solutions to my problem. The code is as follows :

      #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");    
             }
        }

Upvotes: 1

Views: 9110

Answers (2)

unwind
unwind

Reputation: 399813

The member strng is of type nx_string_t, which is not a pointer.

You must compare against the pointer element inside:

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

Upvotes: 4

simonc
simonc

Reputation: 42175

The comparison should be

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

vale->strng is of type nx_string_t which is not a pointer so can never be NULL. It does however have a buf pointer member which could be NULL.

Upvotes: 2

Related Questions