c - Using 'dummy' pointers just for comparison -
i have struct contains string (character pointer).
this string/array should in form of 1 of following:
- contain actual string data
- no actual data, should able show it's in called
state_1
- same above,
state_2
i want able check if 'string' in state_1
or state_2
, , differently if contained actual data. if had 1 state, use null pointer.
i tried along lines of this, leads undefined behavior.
char *state_1, *state_2; ... if(tstruct.string == state_1 || tstruct.string == state_2){ ... }
reserve 2 static addresses. they're guaranteed unique.
static char state_1[1]; static char state_2[1]; if (tstruct.string == state_1 || tstruct.string == state_2) { ... }
these global variables or static locals, either one.
Comments
Post a Comment