c - Using 'dummy' pointers just for comparison -


i have struct contains string (character pointer).

this string/array should in form of 1 of following:

  1. contain actual string data
  2. no actual data, should able show it's in called state_1
  3. 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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -