I. Usage of typedef
In C/C ++, typedef is often used to define an alias for an identifier and a keyword. It is part of the language compilation process, but it does not actually allocate memory space, such:
Typedef int;Typedef int array [10];Typedef (int *) pint;
Typedef can be enhancedProgramBut it also has some disadvantages such as "non-intuitive.
Ii. # define usage
#
Difference between typedef and # define
1. typedef
Typedef is the meaning of the type definition, but itInstead of defining a new type, you can create an alias for an existing type., Similar to the meaning of the reference,References are aliases of variables or objects, while typedef defines aliases of types.. Typedef has two main functions:
1.1 simplify complex type declarations
Simplify complex type declarations, or give existing types an alias
Defining constants is best used with static const, without # defineConstants are often defined when writing code. For example, to write a UI view class, the view is displayed and then the animation is played, and then disappears. You may want to extract the time to play the animation as a constant. People who have mastered Objective-c and their C-language base may do so in this way:#define ANIMATION_DURATION 0.3The preprocessing instructions above rep
The Application of C ++ programming language is flexible. Its appearance has brought a lot of help to programmers. So what are the features of other programming languages? Let's start with the features of the C ++ # define pre-processing command and compare it with other languages.
C ++ # define pre-processing commands define so-called symbolic constants, which a
1. const is used for defining class member variables. Once defined, the value cannot be changed. Define defines global constants that can be accessed anywhere.2. define cannot be defined in the class, But const can.3. const cannot define constants in condition statements.Copy codeThe Code is as follows:If (...){Const FOO = 'bar'; // invalid}ButIf (...){
In C or C + +, you can declare a new type in place of an existing type by using typedef and define. For example:typedef int COUNT;#define COUNT int;Both work by using count to represent an int. Although the two functions are the same, there is actually a big difference, otherwise they will not exist at the same time. The following is a brief discussion of the difference between the two, hoping to use the co
#define N OK#define N 100; Error#define N = + Error int A[n] = int a[=] Error#define PIN int* pin, A, b; Error (A is int*,b int)2. Special usage#define BEGIN {#define END}int main BEGINprintf ("haha");ENDDefine a loop#
Summary:Const is used instead of a fixed value of # define, and inline is used instead of # define a function. is an upgraded version of # define, in order to eliminate the defect of # define.the difference between #define和inlineDefine: defines a macro that is processed during precompilation ;simple character substitut
Macro definitionA macro definition is a definition of some common variables, strings, and so on, and the defined data is automatically replaced in the compilation. Sometimes some variables or strings are used more than once, when the need to modify, you need to the source files where they appear in one by one, the efficiency is low, and through the macro definition, only need to modify the definition, you can achieve batch modification, improve efficiency, or sometimes some numbers or characters
within the STL, the Map,set is implemented using the same red-black tree, the map corresponds to the template parameter key_type,mapped_type, and the set The corresponding template parameter has no mapped_typeboth support insert operationsPair??for Maptypedef pairfor SetTypdef Key_type Value_type;??so in the extension library Pb_ds ( code in ext/pb_ds) It 's designed like this, like trie.Triesays key is string,mapped is intTriesays that key is a string without mapped similar to a trieset conce
Define fact relationships :
You sometimes need to define the dimension of the measurement value based on the data items in the fact data table, or query other specific information in the fact data table, such as the invoice number related to the specific sales situation or the purchase order number. When a dimension is defined based on such fact data table items, the dimension is called a "fact dimension "
Normal07.8 磅02falsefalsefalseMicrosoftInternetExplorer4
The typedef keyword and # define have a common function. A custom name is created for a type, as shown in figure
Typedef int Myint;
# Define Myint int
They are the same, but they are still quite different.
Typedef statements are parsed during compilation, while # define statements are parsed during
1. Definition Format of one-dimensional array typeTypedef For example:(1) typedef int vector [10];(2) typedef char strings [80];(3) typedef short int array [N];The first statementDefines an array type vector whose element type is int and contains 10 elements. If typedef reserved words are not used, the elements are defined as arrays, it only defines an array vector whose element type is int and contains 10 elements. These two definitions have essential differences. If we
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
To define an array type using typedef statements1. Defining formats for one-dimensional array types typedef For example: (1) typedef int VECTOR[10]; (2) typedef char STRINGS[80]; (3) typedef short INT array[n]; The first statement defines an array-type vector with an element type of int, containing 10 elements, and, without a typedef reserved word, becomes an array definition, which defines only an array vector with an element type of int and 10
Use occasion: Splicing two macros, one is the incoming macro. But the incoming macros will not be replaced, but it will be awkward to take them up. After a variety of attempts, incredibly became, hereby record sharing, convenient for everyone to learn.
Char a_param=0;
Char b_pramm=0; Add a macro definition#define OBJECT A#define DEFINE_ (X) x# #_param//Once defined#defi
use define () unless you consider readability, class constants, or focus on micro-optimizations
In PHP, it is customary to use the Define () function to define constants. But starting at some point, PHP can also use the const keyword to declare constants. So when you define constants, which way do you use them?
The an
When writing a program, we often encounter a problem where we need to write a lot of the same code, and the code structure is the same. Always want to encapsulate this code and then call directly, but if this code logic is not complex, and the amount of code is not suitable for encapsulation, then we will think of C + + keyword define. In fact, it is wise of you to meet the above situation and think of something else----template, and we'll talk about
Understanding # define sreg (* (volatile unsigned char *) 0x5f)
Understanding # define sreg (* (volatile unsigned char *) 0x5f)This definition is always very strange. I don't know why. I have a little bit of experience today. Please submit more bricks to the prawns ~~~
Embedded system programming requires programmers to use C language to access a fixed memory address. Since it is an address, according to
using the multi-dimensional dataset wizard, you can easily define a simple multi-dimensional dataset in SQL Server 2005. This wizard helps you define measurement values and dimensions for cubes. In this wizard, you can define a multi-dimensional dataset based on the data source, or you can define a multi-dimensional da
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.