Macro: Use a string to replace an expression code or function call code. Before compilation, the Preprocessor uses the expression code or function call Code represented by this macro string to replace all the macro strings that appear. In this case, the function call Code represented by a macro does not need to open up the function stack, and does not need to protect and restore the function call site. This improves the code execution efficiency, calling a macro is more effective than calling a
1.Inline functions and macros:
Inline extension is used to eliminate the time overhead for function calls. It is usually used for frequently executed functions. A function with a small memory space is very beneficial. So what is the relationship between inline functions and Macros ??
In fact, the functions of inline functions are similar to those of preprocessing m
Generally, our understanding of C/C ++ macros is nothing more than two points:
1. It is used to process repeated inclusion of header files.
2. Macro used to define similar functions. Everyone can understand the first point. Second, we often see macros used to define similar functions. What is more classic: Define max (A, B) (A> B )? (A) :( B) A similar approach is primarily to bypass type checks, in this wa
Record macros in Word 2013 Step 1: Start Word 2013 and open the document, enter the text you want to work with in the document, and then, on the View tab, in the Macros group, click the Macro button and select the Record Macro option in the Open list, as shown in Figure 1. The Record Macro dialog box opens, you enter the name of the macro in the Macro Name text box, and you select the document that you save
You is a C programmer, you must is familiar with macros. They is powerful and can help you ease your work if used correctly. However, if you don ' t define macros carefully, they could bite you and drive you crazy. In the many C programs, you could see a special macro definition which may seem isn't so straightforward. Here is one example: #define __set_task_state (tsk, State_value) do {(tsk)->state = (stat
| _ ioc_write (bidirectional ).The kernel defines the _ IO (), _ ior (), Iow (), and _ IOWR () macros to help generate the above cmd. The following describes the implementation of _ IO (). Others are similar:
You can see the definition of _ IO () in ASM-generic/IOCTL. h.:
# DEFINE _ IO (type, NR) _ IOC (_ ioc_none, (type), (NR), 0)
Let's look at the definition of _ IOC ().:
# DEFINE _ IOC (Dir, type, NR, size )\(DIR) (Type) (NR) (Size)
It can be see
description in section 6.10.3.1 of the standard is still clear, and it writes as follows:
after the arguments for the invocation of a function-like macro have been identified, argument substitution takes place. A parameter in the replacement list, unless preceded by a # Or # preprocessing token or followed by a ## preprocessing token (see below), is replaced by the corresponding argument after all macros contained therein have been expande
Three macro tools I used in vc6
Favorites
New article: Status Bar (3/3)-teststatusbar. Java implemented in Java | old article: Create a class for the filefilter object used by jfilechooser implemented by RegEx
AlthoughHowever, the time to use VC is not short, but I recently noticed that the VC can also customize macros, such as Word and execel. I wrote the following three, which has a good effect and can greatly prolong the service life of the keybo
declare_dynamic macro to the Class header file, and then include this module in all. cpp files that need to access part class objects. If delcare_dynamic and implement_dynamic macros are used as described, you can use the runtime_class macro and cobject: iskindof function to determine the object class during running time. If declare_dynamic is included in the class definition, implemetn_dynamic must be included in the class tool.
Declare_dyncreateDec
1. Question:
C ++ rtti lacks some runtime information and cannot directly create an object based on the object name. To achieve serialization, MFC constructs its own rtti information from the ground up and defines a set of macros. For details, refer to the implementation of the following classes and Macros in the MFC source generation:Cruntimeclass, cobject, declare_dynamic, implement_dynamic
2. Requirement
Some predefined macros are specified in the C standard and are often used in programming. The following table lists some predefined macros that are frequently used.
_ Date _ Date of preprocessing (string text in the form of "Mmm dd YYYY)
_ File _ represents the string Text of the current source code file name
_ Line _ represents the integer constant of the row number in the current source code.
_ Time _
macro to the Class header file, and then include this module in all. CPP files that need to access part class objects. If DELCARE_DYNAMIC and IMPLEMENT_DYNAMIC macros are used as described, you can use the RUNTIME_CLASS macro and CObject: IsKindOf function to determine the object class during running time. If DECLARE_DYNAMIC is included in the class definition, IMPLEMETN_DYNAMIC must be included in the class tool.DECLARE_DYNCREATEDECLARE_DYNCREATE (c
)__attribute__((aligned (n)))To align the structure members to the natural boundary of n Bytes. If the length of a member in the structure is greater than N, the maximum member length is used for alignment.4)__attribute__ ((packed))Cancels the optimization alignment of the structure during compilation and alignment according to the actual number of bytes occupied.The first method above n = 1, 2, 4, 8, 16... is more common.
#define CACHE_ALIGNED __attribute__((aligned(CACHE_ALIGN_SIZE)))3.
Variab
Implement TODO macros by yourself//turn into a string#define STRINGIFY (S) #S// macros that need to be solved two times before they can be solved#define DEFER_STRINGIFY (s) stringify (s)#define PRAGMA_MESSAGE (msg) _pragma (stringify (MESSAGE (msg))// to beWarningAdd more information#define Formatted_message (MSG)"[todo-]defer_stringify (__counter__)"] "MSG"\ n"defer_stringify (__file__)"line"defer_stringif
You can use macros to define "functions" without return values ". For example:
# Define printmax (A, B)/do/{/INT x = A, y = B;/printf ("MAX: % d/N", x> Y? X: Y); //} while (0) //... printmax (3, 4 );
Such a "function" is essentially different from a function in the true sense, because a macro is a pre-compilation behavior and only replaces the text before compilation. In Python source code, we often see macro definitions similar to the following:
Part I: Macro basics A macro is simply a text substitution tool in the C preprocessing phase, which is not visible to binary code after compilation. The basic usage is as follows: 1. Identifier aliases #define BUFFER_SIZE 1024 preprocessing phase, Foo = (char *) malloc (buffer_size);//is replaced with foo = (char *) malloc (1024); Macro body wrapping requires a backslash at the end of the line #define NUMBERS 1, 2, 3 preprocessing phase int x[] = {numbers};//is expanded to int x[] = {1, 2, 3}; 2
How to use macros to print more data, have seen others do, in Excel, she set up a macro, there are a lot of data, names-address-telephone what, like a payroll list just along the distribution, no format. Then you can print it in a good format, only to realize that it is a macro.
Excel on the DOT tool--macros--record a new macro, in the macro name that enter a name you know later. It can then be set to the
Some predefined macros in the C language standard
The C standard specifies some predefined macros that are often used for programming.The following table is a list of predefined macros that are often used.
__date__Date for preprocessing (string literals in the form of "MMM DD yyyy")
__file__string literal representing the current source code file name
__line_
Small series The last time you start word2007, always prompt "Security warning macros have been disabled," but where is this macro? turned the word option over and over, didn't find it! After a burst of Baidu, Google big search just know in the "Trust Center Settings" inside a "macro settings", add this setting is Office A security defense initiative designed to prevent malicious code from using macros to a
commonly used strings , common basic variable definition macros ConstApple has always recommended that we use a const instead of a macro Const Effect : 1. modifier right basic variable or pointer variable int a int *p 2. the const modifier variable is read-only Modifying basic variables//int Const A = 3;//Const int a = 3; int * const p; //P: read-only *p: variable int const * p1; //p1: variable *p1: Read Only const int * p2; //P2:
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.