Conditional Check of #define values in C macros

This code shows condition checking of #define values and also token combining using ‘##’

#include <stdio.h>
#define REQMOTHERBOARD 11
#define BOARD_USERBOARD1 11
#define BOARD_USERBOARD2 12
#define MB(board) (REQMOTHERBOARD==BOARD_##board)

int main(void) {

   printf("Testing defines\n");

   #if MB(USERBOARD1)
      printf("Board available!");
   #else
      printf("Board not available");
   #endif

   return 0;
}

About PraveenMax
My Interests: ------------------ Programming , Drawing & Music

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: