#if #elif Considerations when using #define TypeDef

Source: Internet
Author: User

Let's say the following code is required to be compatible with three versions


This will not complete the task.

No matter


typedef enum{first,second,third,}; #define NUM  third#if (num = = first) #define  VAR  1#elif (num = = SECOND) # Define  var  2#elif (num = = third) #define  var  3#endifint main (void) {#if (num = = first) printf ("VAL =%d\n" , Var), #elif (num = = SECOND) printf ("val =%d\n", var), #elif (num = = third) printf ("val =%d\n", var); #endif}

#define NUM First or

#define NUM Second or

#define NUM Third

The results are all the same



But then we can do the job.


#define FIRST    1#define SECOND   2#define third    3#define num  third#if (num = = first) #define  VAR  1#elif (num = SECOND) #define  var  2#elif (num = = third) #define  var  3#endifint main (void) {#if (num = = First) printf ("val =%d\n", var), #elif (num = = SECOND) printf ("val =%d\n", var), #elif (num = = third) printf ("val =%d\n", var); #endif}


#define NUM First or

#define NUM Second or

#define NUM Third

Can get the results you want.



Why?????





#if #elif Considerations when using #define TypeDef

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.