This article provides a detailed analysis of the differences between static, const, and define in php. For more information, see
Define section:Macros can be used not only to replace constant values, but also to replace expressions or even code segments. (Macros have powerful functions but are prone to errors, so their advantages and disadvantages are quite controversial .)
Macro syntax:#
In C/C ++, we usually write
Program The typedef keyword and # define macro definition commands may often be used. In some cases, using them will achieve the same effect, but they have substantial differences, A keyword is C/C ++, a macro definition command is C/C ++, and typedef is used to create an alias for an existing data type, # define is used to define a m
In C/C ++, we usually use typedef keywords and # define macro-defined commands to write programs. In some cases, using them will achieve the same effect, however, there are substantial differences. One is the keywords of C/C ++ and the other is the macro definition commands of C/C ++, typedef is used to create an alias for an existing data type, and # define is used to
at the time of definition ;(2) After initialization of the constant variable, it is not allowed to be assigned again ;4. Example#include Operation Result: $Third, const (c + +) and # define language 1. The constants defined by the const are different from the symbolic constants defined by # define(1) constants defined by a const have a type, whereas a # define d
Const
Used to define constant values that cannot be changed at run time. Once defined and cannot change its value, an error occurs if the value is changed in the program.
The code is as follows
Copy Code
CALSS math{Const pi=3.14159;}echo Math::p i;?>
There is no dollar sign ($) before and can be useful without initializing the class. The constant value must be a constant expression. const-defined variables that
#define EC (x) l# #x role Description
Indicates L is connected with X.
#define CONN (x,y) x# #y
#define TOCHAR (x) #@x
#define TOSTRING (x) #x
x# #y表示什么? Represents x connection Y, for example:
int n = Conn (123,456); The result is n=123456;
char* str = Conn ("asdf", "ADF") the result is str = "ASDFADF";
It's a
in our previous article, we introduced the use of PHP define examples, I believe that we have a certain understanding of define, today we introduce you to the PHP constant define and the difference between const detailed!
A constant is a simple identifier. This value cannot be changed during script execution (in addition to the so-called magic constants, they a
Difference between typedef and # define ------ [Badboy ],
Typedef and # define are commonly used to define the alias of an identifier and a keyword, but there is a key difference between them.
Typedef is part of the language compilation process;
# Define is a macro Definition Statement, which is not carried out during
Const and define all define constants in PHP, but what are their specific differences? In fact, very simple const is used for the definition of a class member variable, once defined and cannot change its value. Define defines a global constant that can be accessed anywhere the page define cannot be defined in the class
C # preprocessor directives are never translated into executable code commands, but can affect all aspects of the compilation process, common preprocessor directives have # define, #undef, #if, #elif, #else和 #endif, and so on, the following describes C # use # Define an instance of conditional compilation.In C #, conditional compilation directives are used to conditionally include or exclude portions of a s
# DefineCreate a macro that is an identifier or parameterized identifier associated with the tag string. After defining the macro, the compiler can mark a string to replace each matching item of the identifier in the source file.Syntax
# DefineIdentifierToken-string
# DefineIdentifier(Identifier1,...,IdentifierN)Token-stringRemarks
1 # defineCommand to enable the CompilerToken-stringReplacing the source fileIdentifier. Only whenIdentifierIt is replaced only when a tag is formed. That is to say,
Usage of "#" and "#" in macroI. general usageWe use # to convert the macro parameter into a string, and # to combine the two macro parameters.Usage:# Include# IncludeUsing namespace STD;
# Define STR (s) # s# Define cons (a, B) int (A ## e ## B)
Int main (){Printf (STR (vck); // output string "vck"Printf ("% d/N", cons (2000); // 2e3 output:Return 0;}
2. When the macro parameter is another macroIt should be
A constant is a simple identifier. This value cannot be changed during script execution (in addition to the so-called magic constants, they are not constants). Constants are case sensitive by default. Usually, constant identifiers are always uppercase.You can use the Define () function to define constants. After php5.3.0, you can use the Const keyword to define c
When defining constants in PHP, you can use both the const and define methods, so what's the difference between them?1.const the definition of a class member variable, once defined, cannot be modified. Define is not available for definition of class member variables and can be used for global constants.2.const can be used in a class, define cannot.3.const You can
Define section:Macros can be used not only to replace constant values, but also to replace expressions or even code segments. (Macros have powerful functions but are prone to errors, so their advantages and disadvantages are quite controversial .)
Macro Syntax:# Define macro name macro value
As a suggestion and a common habit of programmers, macro names often use uppercase letters.
Advantages of macros:1)
Difference between const and # define,
(1) Different compiler Processing MethodsThe define macro is expanded in the preprocessing phase.
Const constants are used in the compilation and running phase.
(2) Different Types and security checks
The define macro has no type and does not check any type. It just expands.
Const constants have specific types. during compil
This article mainly introduces how to use mini-define to implement modular management of front-end code. it is a very good article. we recommend it to partners who need it.
Mini-define
A simple front-end modular framework based on require. If you don't want to spend time learning require. js or look at the long cmd/amd specifications, then this mini-define is yo
Correct use of IOS macros (define) and constants (const)In iOS development, macro definitions are often used, or some data types are modified with const, and often developers do not know how to use them correctly, resulting in the confusion of macros and const decorations in the project.Can you distinguish between the following? Do you know when to use it?#define Hscoder @"Hansha haha"nsstring *hscoder = @
Define section:Macros can be used not only to replace constant values, but also to replace expressions or even code segments. (Macros have powerful functions but are prone to errors, so their advantages and disadvantages are quite controversial .)Macro Syntax:# Define macro name macro valueAs a suggestion and a common habit of programmers, macro names often use uppercase letters.Advantages of macros:1) make
Not only can you define constants in C + + define , but you can also const define constants with the following differences:
A #define MAX 255 defined constant is no type, given an immediate number, the compiler simply links the defined constant value to the name of the defined constant,
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.