LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

#if not working with enums

Solved!
Go to solution

Hi,

Is there a way to make preprocessor accept enums to make example bellow work as it is? (I haven't digged into the ansi C spec for this)

 #include <ansi_c.h>
/*
#define TEST1        (0)
#define TEST2        (1)
#define TEST3        (2)
#define TEST4        (3)

#define ALL_TESTS (4)

*/
typedef enum {TEST1, TEST2, TEST3, TEST4, ALL_TESTS} TESTS;
#define DO_TEST  (TEST3)


int main(int argc, char *argv[])
{
  char *names[] = {"one", "two", "three",  "four"};
  TESTS i;
  //int i;
  int index;
#if !defined(DO_TEST)
  printf("Please define DO_TEST e.g. #define DO_TEST (TEST3)\n");
  goto end;
#elif (DO_TEST == ALL_TESTS)
  for(i=0; i<ALL_TESTS; i++)
  {
#else
  i=DO_TEST;
#endif
 
  printf("name[%d] = %s\n", i, names[i]);
#if defined(DO_TEST) && (DO_TEST == ALL_TESTS)
  }
#endif
end:
  getchar();
  return 0;
}

0 Kudos
Message 1 of 2
(3,029 Views)
Solution
Accepted by topic author E351635

I think you're on a loser, here. enums are not part of the preprocessor subsystem of a C compiler, so of course #if will not work with them.

 

JR

Message 2 of 2
(3,025 Views)