Has no member compilation error

I have the following code, and when I try to compile it, I get an error message:

error: 'list_item_t does not have a name named' state

Any creative ideas on how to make this part of the code compile without warnings and erros?

#if defined (_DEBUG_) #define ASSERT assert #else /* _DEBUG_ */ #define ASSERT( exp ) ((void)(exp)) #endif` typedef struct list_item { struct list_item *p_next; struct list_item *p_prev; #ifdef _DEBUG_ int state; #endif } list_item_t; main(int argc, char *argv) { list_item_t p_list_item; ASSERT(p_list_item.state == 0); } 
+1
source share
3 answers

Just #define ASSERT like

  #if defined (_DEBUG_) #define ASSERT assert #else #define ASSERT( exp ) (void)0 #endif 

Please note that this can change the behavior of other code spots, because ASSERT no longer evaluates its argument, but the way people expect it to behave anyway.

Or execute the _DEBUG_ construct, but this will not solve the problem, it just avoids it.

+3
source

Your class has the mentioned member if and only if _DEBUG_ defined, and apparently this is not so.

#define _DEBUG_

at the beginning of your TU or change project settings to define it in some other way.

+2
source

It's connected with

 #define ASSERT( exp ) ((void)(exp)) 

which evaluates to p_list_item.state == 0 and therefore needs a state to exist, even if _DEBUG_ not #define 'd.

+2
source

Source: https://habr.com/ru/post/895375/


All Articles