Home > Back-end >  Pre compiler macro substitution
Pre compiler macro substitution

Time:10-23

Who help to give a simple "macro substitution part" in the compiler source code,,,, c or c + +, thank you,

CodePudding user response:

From the top,,,,,,,,

CodePudding user response:

 
# define MSG (STR) ShowMessage (STR);

MSG (" hello ");

CodePudding user response:

refer to the second floor ksrsoft response:
 
# define MSG (STR) ShowMessage (STR);

MSG (" hello ");


Take this example, should be changed to:
 # define MSG (STR) ShowMessage (STR) 
MSG (" hello ");

Or
 # define MSG (STR) ShowMessage (STR); 
MSG (" hello ")

Pay attention to the subtle differences,

CodePudding user response:

A long time, and to find out, how a semicolon!

CodePudding user response:

CodePudding user response:

I am want oneself to the compiler, simple, and lack of implementation of macro substitution,

CodePudding user response:

reference 5 floor ccrun reply:

I am want oneself to the compiler, simple, and lack of implementation of macro substitution,

CodePudding user response:

reference 5 floor ccrun reply:

I am want oneself to the compiler, simple, and lack of implementation of macro substitution,

CodePudding user response:

Didn't know what you mean,

CodePudding user response:

Now I want to be a simple compiler, contains only "function of macro substitution", and strives for the code,
The basic meaning is: open a TXT file, search for macro substitution command line (such as # define MAX=100) , are in the program will be behind MAX in 100; There is no need not operation,,,, don't have time to write, feeling is not very difficult,

references 9 f ccrun response:
didn't know what you mean,

CodePudding user response:

Later in the program of MAX in 100? What is the Max file for 100 or code judgment!

According to the thinking of you, isn't it more suitable to a macro definition
# deinfe Max
 
# ifdef Max
.
# endif

CodePudding user response:

The
references to the tenth floor u010472855 response:
now I want to be a simple compiler, contains "function of macro substitution", only, strives for the code,
The basic meaning is: open a TXT file, search for macro substitution command line (such as # define MAX=100) , are in the program will be behind MAX in 100; There is no need not operation,,,, don't have time to write, feeling is not very difficult,

The demand is somewhat complicated, you need to do code formatting, and semantic analysis, etc...

CodePudding user response:

The
refer to 12 floor ccrun reply:
Quote: reference to the tenth floor u010472855 response:

Now I want to be a simple compiler, contains only "function of macro substitution", and strives for the code,
The basic meaning is: open a TXT file, search for macro substitution command line (such as # define MAX=100) , are in the program will be behind MAX in 100; There is no need not operation,,,, don't have time to write, feeling is not very difficult,

The demand is somewhat complicated, you need to do code formatting, and semantic analysis, etc...

Without semantic analysis, as long as find the macro definition, such as Max. Replace with 100

CodePudding user response:

The
reference 11 floor ksrsoft response:
behind program of MAX in 100? What is the Max file for 100 or code judgment!

According to the thinking of you, isn't it more suitable to a macro definition
# deinfe Max
 
# ifdef Max
.
# endif

That let you write a code to open a TXT file, find file have any macros replace such as # define Max 100. There is no need not operation, so will file all other Max in 100, is the realization of a macro substitution, don't have the function of macro substitution, just simple values of macro substitution
  • Related