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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -