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
Macros in C language are used to indirectly operate the compiling environment.
C language: Before compiling the source program normally, explain some special preprocessing commands to generate a new source program, then perform the normal compilation (to obtain the intermediate file and add the parameter/p ).
In the source program, in order to distinguish preprocessing commands from General C statements, all preprocessing command lines start with a sy
Access using macro control program 3. Use Conditions in macros
Access using macro control program 3. Use Conditions in macros
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 o
The assert macro prototype is defined in the header file assert. in h, it is used to terminate the execution of the program if the condition following the macro returns false. The macro will call the _ assert_fail function, which first outputs error information to stderr, then, call the abort function to terminate the program execution.
1. assert macro definition
As follows:
[Cpp]# Define assert (expr )\(Expr )\? _ ASSERT_VOID_CAST (0 )\: _ Assert_fail (_ STRING (expr), _ FILE __, _ LINE __, _ A
PowerPoint custom operations to trigger malicious Payload instead of macros
When analyzing recent phishing attacks, we found that attackers started to use PowerPoint custom operations to trigger malicious Payload instead of macros. Although the use of PowerPoint attachments is not new, this attack is still interesting because they can bypass the Office attachments to enable Macro Controllers.
1. Attackers
C languageThe use of macros (macro) in macro C (and C + +) belongs to the scope of compiler preprocessing, which is a compile-time concept (not a run-time concept). The following is a simple summary of the use of macros encountered. About # and # #In a C-language macro, #的功能是将其后面的宏参数进行字符串化操作 (stringfication) is simply to add a double quotation mark to the left and right of the macro variable that it refers
Many Program Personnel do not know C What does "macro" mean? Especially When a macro has Parameters Macro and function are often confused. I want to talk about "macro" here ", Macro only A definition defines a statement block. When a program is compiled, the compiler first needs to execute an action to replace the source program and replace the macro reference with the macro-defined statement block, just like replacing a text file. This action term is "macro expansion ". Using
When writing code yesterday, you must obtain the current Compilation Time in the code to dynamically use the version information. Therefore, some predefined Macros in the C standard are used. Here we will summarize the following macros defined in the C standard:
_ Date _ Date of preprocessing (string text in the form of "Mmm dd YYYY", such as May 27 2006)_ File _ represents the string Text of the curre
An inline function is also called an embedded function.
Program .
Function calling requires the establishment of a stack memory environment, parameter passing, and program execution transfer, which requires some time overhead.
The Inline Function Definition in C ++ is very simple. You only need to add a keyword inline before a common function. In addition, there is no difference (including the function call method) with the ordinary function on the surface ), because of this, in the opinion of
The Inline Function Format is as follows:
Inline int FAC (int I) {return I * I ;}
Inline functions, like common functions, require reference type checks, but it is more efficient to execute inline functions than to execute common functions, because calls to inline functions do not need to be interrupted, inline functions are embedded into the target during compilation.CodeMedium.
Applicable scenarios:
1) the code is short and does not include loops.
2) need to be called repeatedly
The
A collection of non-MFC program trace and assert macrosWe know that the trace and assert macros come with the MFC framework program. But how can we implement these two Macros in a non-MFC program. Here is an implementation method. Implement these two Macros in the Debug. h file. The program can include this header file. The header file and description are as foll
We know that the trace and assert macros come with the MFC framework program. But how can we implement these two Macros in a non-MFC program. Here is an implementation method. Implement these two Macros in the Debug. h file. The program can include this header file. The header file and description are as follows:
# Ifndef _ debug_h _# DEFINE _ debug_h _
# Ifndef
How to Use Macros in C language, including Single and Double Well variable parameters
Favorites
Macros (macro) in C (and C ++) belong to the scope of compiler preprocessing, and belong to the concept of compilation period (rather than the concept of runtime ). The following briefly summarizes the frequently encountered macro usage problems.
About # And ##
In the macro of C language, # is used to stringize t
iOS uses macros to define functions and blocks of codeToday, in the development process, there is a problem: it is the parent class to send out notifications, and then in the subclass or other class to receive it. Of course, it is generally written into the class method, but there is a problem, that is, if the calling class is not its subclass, it can not be directly invoked, of course, it is also possible to implement the static method, I am here mai
v1--Single-parameter macros#define DRV_DEBUG 1#if DRV_DEBUG #define DRV_PRINT(x) printf(x)#else #define DRV_PRINT(x) #endifThis version of Drv_print (x) can only output a single variable--pure stringvoid foo(){ DRV_PRINT("Driver Initialize Success!");}Change the Drv_debug macro definition when you do not need to print debug information#define DRV_DEBUG 0Of course, you can define it directly.#define DRV_PRINT printfBut if the macro calls more tha
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.