Write a good-looking macro definition in C language. Using macro definition can prevent errors, improve portability, readability, and convenience. The following lists some macro definitions commonly used in mature software ......1. prevent a header file from being repeatedly contained# Ifndef comdef_h# Define comdef_h// Header file content# Endif2. redefine some
Macro definition ' DefineRepresents a string with a specified identifier (that is, the name), which is in its general form:' Define identifier (macro name) string (macro content)such as: ' Define signal stringIts function is to specify the identifier signal instead of string, in the process of compiling preprocessing, all the signal after the command is replaced
A single line definition of a macro#define A (x) t_# #x#define B (x) #@x#define C (x) #xWe assume: x=1, then there are:A (1)------〉t_1B (1)------' 1 'C (1)------"1"
. How to define macros, cancel macrosDefining macros#define [macroname] [Macrovalue]Cancel macros#undef [macroname]Common macros#define PI (3.1415926)Macros with parameters#define MAX (A,b) ((a) > (b)? (a), (b))The key is very easy to produce errors, including machine and human understan
? macro definition:
In a program, the start of a # is a preprocessing instruction.#define定义宏常量can appear anywhere in the code.
As shown in the following illustration:To determine whether the macro definition is correct, to take the content of the macro definition to the real program, according to the actual program.
#define从本行开始, this
Impressions of the first C + + exam: Before the exam: fool I am crazy;Examinations: Full of ridiculous words of paper;Test finished: a bitter tear;After the exam: Who knows which regrets. Alas! Let's not do it!!! /span> Last time did not listen to command, test before assault, hit the south wall, this time should turn back! So the first stage followed the big troops: The book slipped over, first of all, a general mind map
Like to read some Open-source project source, always will find that the great God's code always have some short and efficient macro definition, click to see, find obscure, not to mention learning, sometimes understanding is a difficult, but the macro definition itself is not so difficult, But write a good macro of course still need rich experience and technology,
Write in frontThanks to all the friends who came in to see. Yes, I'm currently going to write a book about unity shader.The purpose of the book is to have the following several:
Summarize my experience with unity Shader and give others a reference. I am very aware of the difficulties of learning shader, and I have seen many questions raised by people in the group. I think learning shader is still a
See in the book with macros to debug, looks very troublesome, but for the big project, is a good habit.Very small code is currently written ... It is not available for the time being.But write down some of the useful search for the debug macro URL, it might be used in the future.
http://blog.csdn.net/cp1300/article/details/7773239 printf's macro definition
an object-based, process-oriented learning to a completely object-oriented transition. At first, I always find it difficult to climb, now think about it is also very simple, but learning, these simple concepts clear, or there will be other knowledge waiting for us to pursue, such as the last chapter string processing the contents of strings, it is also worth to do a bit of accumulation of drip. Summary:The first time I read it quickly, the whole book
(p) directly to the backend regardless of whether the safe_free (P) is in uppercase;For exampleIf (null! = P)Safe_free (P );Else// Do somethingExpandedIf (null! = P){Free (p); P = NULL ;};Else// Do somethingThis still causes if and else matching to be damaged.If you use the famous Method# Define safe_free (p) do {free (p); P = NULL;} while (0)SoIf (null! = P)Safe_free (P );Else// Do somethingExpandIf (null! = P)Do{Free (p); P = NULL ;}While (0 );Else// Do somethingOkay, it's okay.This is what t
I didn't like macros much when I started to use the C language.
Code I also have to understand.
Macros can be defined in the sourceProgramBut is usually placed before. Data.Some simple macros can be replaced by equ, textequ, OR =, but macros have more complex functions.
The essence of "macro" is "Replacement", but it is like "sub-process ";Therefore, there are both macro processes and
directory of this document
Introduction to preprocessing Directives
One, macro definition without parameters
Second, macro definition with parameters
Description: This C language topic is the prelude to learning iOS development. And for programmers with an object-oriented language development experience, you can quickly get started with C language. If you don't have programming experie
Introduction to preprocessing Directives
One, macro definition without parameters
Second, macro definition with parameters
Description: This C language topic is the prelude to learning iOS development. And for programmers with an object-oriented language development experience, you can quickly get started with C language. If you don't have programming experience, or are no
Http://tech.e800.com.cn/articles/2009/727/1248665385863_1.html
Many C ++ books advise us that C language macros are the first of all evil, but things are not as bad as we think, just like Goto. MacroA major role is to automatically generateCode. If the template can generate various types of code (type replacement) for us ),In fact, macros can generate new Code (replacement and addition of symbols) on the symbols ).
You can find some macro Synt
In C and C + + languages, an identifier is allowed to represent a string, called a macro, which can be a constant, an expression, a string of formatting, and so on. When compiling preprocessing, all occurrences of the "macro name" in the program are substituted with the string in the macro definition, which is called "macro
(a) Symbolic constantsA macro definition is a substitution policy in C that uses a preprocessing command #define equate a string (lengthy) text with a name (called a macro) and then use the macro in bulk in the source code. In the preprocessing phase, replace the macros in the source code with the original text. For example, in the source code:#define PI 3.14T
" H.264/AVC Video Codec technology detailed" video tutorial has been in the "CSDN College" on-line, the video details of the background, standard protocol and implementation, and through a practical project in the form of the standard of the resolution and realization of H. A, welcome to watch.
"The paper came to the end of the light, I know this matter to preach", only by themselves in accordance with the standard document in the form of code to operate, in order to the video compression codi
Macro definition of C Language notes
(1) Symbolic Constants
Macro definition is a replacement strategy in C language, that is, using preprocessing commands # define equals a string of (lengthy) texts with a name (macro, then you can batch use Macros in the source code. In the preprocessing phase, replace the macro in t
1. Rules and usage resolution for macro definitions(1) The parsing rule of a macro definition is that it is replaced by a preprocessor during the preprocessing phase, and the substitution is unchanged.(2) The macro definition substitution is performed recursively until the replaced value itself is no longer a macro.(3)
Write in frontThanks to all the friends who came in to see. Yes, I'm currently going to write a book about unity shader.The purpose of the book is to have the following several:
Summarize my experience with unity Shader and give others a reference. I am very aware of the difficulties of learning shader, and I have seen many questions raised by people in the group. I think learning shader is still a
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.