I have the following code and when I'm trying to compile it, I get an error:
error: ‘list_item_t’ has no member named ‘state’
Any creative ideas how to make this piece of 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);
}
Just
#define
ASSERT
asNote that this may change the behaviour of other code spots because
ASSERT
no longer evaluates its argument, but that's how people expect it to behave anyway.Or perform a
_DEBUG_
build, but this doesn't resolve the problem, it just avoids it.Your class has the mentioned member if and only if
_DEBUG_
is defined, and it apparently isn't.#define _DEBUG_
in the beginning of your TU or change project settings to define it in some other way
This is due to
which evaluates
p_list_item.state == 0
and thus needsstate
to exist even when_DEBUG_
is not#define
'd.