C language #define Mosaic macro definition Implementation __c language

Source: Internet
Author: User

Use occasion: Splicing two macros, one is the incoming macro. But the incoming macros will not be replaced, but it will be awkward to take them up. After a variety of attempts, incredibly became, hereby record sharing, convenient for everyone to learn.

Char a_param=0;

Char b_pramm=0; Add a macro definition

#define OBJECT A
#define DEFINE_ (X) x# #_param//Once defined
#define DEFINE (x) define_ (x)//re-defined

#define PARAM define (OBJECT) void Fun ()

{

Define_ (OBJECT) = 100; This operation is rejected, it is the direct stitching is not replaced

DEFINE (OBJECT) = 100; This operation is God, first replace and then splicing, we just made two definitions, solve all the trouble

param=100;//this is okay.

}

That ultimately is not to achieve your goal, the essence of the principle is probably the replacement and stitching sequence, I did not study carefully.

Here is a use of my occasion.

#define STEP_TIMX 4//TIM4
#define STEP_CHX 2//CH2

#define SET_STEP42_PPS_1 (num,x) tim# #NUM->psc= ((X))

#define SET_STEP42_PPS_2 (num,x) set_step42_pps_1 (num,x)

#define SET_STEP42_PPS (X) set_step42_pps_2 (step_timx,x)

The ultimate goal is to achieve tim4->psc=x, my goal is to achieve




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.