Troubleshooting Tips Macro Definitions Cannot Be Changed At RuntimeAugust 25, 2021
This user guide is designed to help you if you find that macro definitions cannot be changed to a runtime error code. Macros are replaced with their preprocessor values long before your source file is even compiled. There is no way to change the value of your current macro at runtime. If you could explain a little more about the goal that you are definitely trying to achieve, there is another way to solve your problem that does not have macros.
You change the specific macro yourself; H. what it provides, but you can change the meaning of the inclusive concept of a macro. For a very absurd example:
#define UNCHANGEABLE_VALUE 5#define CHANGEABLE_VALUEfooint foo = 5;int main () printf ("% d% d n", CHANGEABLE_VALUE); unchangeable_value, CHANGEABLE_VALUE is 10; printf ("% d% d n", CHANGEABLE_VALUE); immutable_value,
Thus, the answer to your topic depends on the type of damage your change should do to the code that uses most of the macro.
5 is compile time, although it is constant and
foo is not, so it won’t work if you plan to port
VALUE always as a
Remember that there are two (actually more) translation times for the primary element C. Inside the first (of our interest) there are additional macros. Once all this is done, each program is "parsed and semantically" compared to 220.127.116.11/2. These steps are often referred to as “preprocessing” and “compiling” (although the translation process is also often ambiguous and broadly referred to as “compiling”). They can even be implemented by separate programs, with the "compiler" acting as a "preprocessor", if necessary, before doing anything else. Thus, the execution is such that alreadyIt's too late to try to go back and change what the last macro reveals.
The preprocessor supports text macro replacement. Replacement of the functional type of text macros should also be supported.
| ||(3)||C ++ 11)|
| ||(4)||(since C ++ 11)|
#define directives define this identifier as a macro, that is, they ask this compiler to replace all sequential ones identifiers and identifiers of occurrences by a replacement list, which, possibly, can be processed additionally. If the person ID is already defined as an existing macro type, the program is in error, unless the definitions are indistinguishable.
Object type macros
Object type macros replace almost all occurrences defined by identifiers in the replacement list. (1) The version of the
#define statement behaves exactly the same.
Function type macros
Functional type macros replace each occurrence of a delimited identifier with an optional substitution list using a series of arguments, which then replace the corresponding occurrences of one of the substitution list parameters.
The syntax for calling a function type macro is very similar to that for calling a process: each instance of your current macro name followed by (thus, the next preprocessing token is a sequence of tokens presented around the list of substitutions. the sequence also ends with the corresponding char Lom), where intermediate pairs of pairs on the left, including square brackets, and right brackets are ignored.
For version (2), this number of arguments should roughly correspond to the number of aspects in the macro definition. For modules (3,4), the number of arguments should always be greater (up to C ++ 20), at least the same (starting from C ++ 20) than the percentage of parameters (without
... ). Otherwise, the program will be poorly formatted. If a person's identifier is not in functional notation, that is, there are no square brackets after the method itself, not everything is replaced. (2)
The version of the
#define directive describes a simple macro of a functional type.
Version (3) of the
#define directive specifies that it is easiest for you to have function type macros with variable number arguments. Additional arguments (called aspect arguments) are available with an identifier
__VA_ARGS__ , which is then replaced with inconsistencies, which are returned with an identifier that will be replaced automatically.
Version (4) of the
#define information defines a function type macro with othernumber of arguments, but without the usual problems. (Named Argument Distinguishing Arguments) are only available if they have the identifier
__VA_ARGS__ , which is then substituted in the arguments that come with the identifier to be replaced.
For versions (3, 4), the replacement list could probably contain a sequence expression
#define F (...) f (0 __VA_OPT __ (,) __VA_ARGS__)# define g (x, ...) f (0, __VA_OPT __ (,) x __VA_ARGS__)#define SDEF (name, ...) S name __VA_OPT __ (= __VA_ARGS__)F (a, s, c) // replaced with f (0, a suitable, b, c)F () // replaced with f (0)G (a, b, c) // replaced with f (0, a, b, c)G (a,) // replaced created by f (0, a)G (a) // replace with f (0, a)SDEF (foo); // replaced with S foo;SDEF (columns, 1, 2); // replaced with S bar = 1, a pair;
|(since C ++ 20)|
Note: if a macro argument of a certain function type contains commas that are definitely not protected by matching pairs in left and right brackets (most of them sometimesoccurs in template argument lists, as in assert (std :: is_same_v
Reserved Macro Names
A language translation unit containing the standard library for h2 tags should not declare any name
#undef in the standard header library.
A translation unit using part of the standard library may not be lexically identical to
|(since C ++ 20)|
In functional type macros, any type of operator
# before a large identifier in the list of replacements leads each identifier through a parameter substitution, and the result of Clos is quoted, effectively creating another string literal al. ... In addition, a specific preprocessor will add a backslash to hide statements around inline string literals, if taken into account, and double backslashes for that specific line, if necessary. All leading and even trailing spaces are removed, and any particular sequence of spaces in the middle of the text (but not in inline string literals) is truncated, so you can use a single space. This is called "stringification". If the result of all string conversions is not valid Is, String, the behavior is undefined.