Write a good C language. A beautiful macro definition is very important. Using a macro definition can prevent errors, improve portability, readability, and convenience. The following lists some mature software commonly used macro definitions ......
1. prevent a header file from being repeatedly contained
# Ifndef comdef_h
# Define comdef_h
// Header
a normal function declaration. We must define the function body.
Inline tablefunction (int I) {return I * I };
Application of restrained functions:
Application 1: define access functions for class member variables
Inline functions are the most widely used in C ++ classes and should be used to define access functions. Generally, data members are defined as private or protected in the classes we define. In this way, the outside world cannot directly read and write the data of our class me
), Io:format ("Show M: ~p ~n", [M]).The code it compiles is:Show ({man,_,_,_} = M) when TrueIo:format ("Show M: ~p ~n", [M]).MacroIt's hard to imagine how hard it is to read our Erlang code without a macro, with magic number everywhere; simply summarize the use of macros in Erlang:
Macro constants such as-define (TIMEOUT, 1000). -define (Servername,my_first_game_server).
With macros such as:-define (E
1. nvelocity ParametersExample:1. Establish a macro# Macro (test $ range $ arraylist)...# End2. macro call# Test ([-9,-1] ["favorite", "color"])In the preceding example, you only need a # macro command that provides the name for each parameter to be passed. These parameters are separated by spaces. In the above example
You can use Word macro commands to increase your productivity when you edit a document using Word. By default, the security setting for Word macros is high, and macros are automatically disabled when you run the Word Macro command. If you set the Word macro security to Medium, the Word Macro Security warning dialog box
For security reasons, many people add passwords to Office documents and, for memory purposes, may use the same password for all Office documents. However, it is cumbersome to repeat the process of document encryption every new document is edited. Here's a good way to automatically add a unified password to all of the specified Office documents, and we'll take word 2007 for example.
STEP1: First click the "view → macro → record
When tuple is used in Erlang, the order and quantity of data items are determined. Once the order of data items is adjusted or the field is increased or decreased, badmatch is easy to appear.
At the same time, if some constants are hard-coded into the Code, once the value changes, it is difficult to replace them with new ones reliably.
The corresponding solutions in Erlang are as follows:Record macro
Record
In the code, we create a record:-record (man
The _ inline keyword has been compiled and tested using keil4 arm. The difference between macro definition and inline function is verified.
Both macro-defined and inline functions do not generate code segments, and the program runs without the parameter pressure stack overhead.
The Inline Function checks the validity of the called parameter, and can also convert the parameter type.
I. The Inlin
In some cases, you may want to perform one or more operations in a macro only when the specified condition is true. For example, if a macro is used to verify data in a form, the corresponding information may be displayed to respond to certain input values of the record, and the other information to respond to different values. In this case, you can use conditions to control the
1. When a function is called, The Program must jump to the memory address space of the called function, then run the Code of the called function. After the called function is executed, the program returns to the previous position to continue execution. In this case, you need to save the on-site address and remember the executed address before the program jump, recover the on-site address after the switch back, and continue the execution according to the original saved address. in this way,
1. macro definitions in the C language (1)#define is one of the unit entities processed by the preprocessor (therefore, the preprocessor simply replaces it and does not(2)#define defined macros can appear anywhere in the program (including inside the body of the function)(3) This macro can be used by code after #define Definition2. Defining Macro Constants(1)#de
Many experts like to use the "macro" command to improve office productivity. However, when you use macros in a Microsoft Office program, a macro security warning pops up, especially when you make a personal resume table, you often need to use a macro, and each time you open it, it makes the user feel more troublesome. If you set the security level of the
Application of Variable parameters in macro definition in C Language
In the C standard library, input and output functions of printf, scanf, sscanf, sprintf, and sscanf are variable parameters. When debugging a program, we may want to define a variable parameter output function to record logs. Using a variable parameter macro is a good choice.
InC99A macro can al
There is a macro _ countof in stdlib. H, as follows:
Extern "C ++"{Template Char (* _ countof_helper (unaligned _ countoftype ( _ array) [_ sizeofarray]) [_ sizeofarray];
# DEFINE _ countof (_ array) sizeof (* _ countof_helper (_ array ))}
This macro is used to obtain the size of an array element.
Use:
# Include
Int main ()
{
Int A [5];
......
Int arraysize = _ countof (a); // obtain the size of array.
}
/
Macro diversity
In wireless communication, macro diversity refers to the situation where multiple sending antennas or multiple receiving antennas transmit the same signal, and the distance between these antennas is much greater than the wavelength. In a cellular network or wireless LAN, these antennas can be located at different base stations or access points. Macro
Annotations are indispensable to help others or themselves read their own programs. A beautiful program is not about how advanced the technology you use, but about how easy it is to describe.
In the Java IDE environment-Eclispe, there are many annotations, and setting annotations is also very convenient, because currently C ++, Xi, and Eclispe have been uninstalled, for setting comments, Baidu or Google is the only option.
So I am used to the comments of Eclispe, so I tried to try it in VC6.0. H
The former array carefully re-examined the macro expansion of C. In summary, there are several main rules:
The results of each macro expansion are scanned repeatedly until there are no expandable macros.
Each time you expand a macro, you will remember this expansion, and in the result of the macro expansio
to prevent CSRF and forms are repeated, some systems use token mechanism, specific mechanisms can be self-study, which for our individual testing caused a certain inconvenience. Solution Ideas:1 , will get token the action is set to macro, which automatically completes each re-acquisition token operation (most time-saving, but troublesome)2 , the test phase allows development to token set to a fixed value (most convenient)3 , all tests are used Proxy
Benefits of using Do{}while (0) in macro definitions#define MACRO_NAME (para) Do{macro content}while (0)Format, summed up the following reasons: 1, empty macro definition to avoid warning: #define FOO () do{}while (0) 2, there is a separate block, can be used for variable definition, a more complex implementation. 3, if the m
parameter. 2) Then use the Va_start macro to initialize the variable arg_ptr, the second parameter of this macro is the first parameter of a variable parameter of , is a fixed parameter. 3) Then return the variable parameters with Va_arg and assign the value to the integer J. The second parameter of Va_arg is the type of the parameter you want to return, and this is the int type. 4) Finally, the Va_end
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.