In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what is the special standard defined and used in the C language". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the special standard defined and used in the C language" can help you solve your doubts.
1. ANSI C special standard definition lists some common special definitions:
_ _ FILE__: path and file name of the file being compiled
_ _ LINE__: the line number of the file being compiled
_ _ date string at compile time of DATE__: such as "July 19 2019"
The time string of _ _ TIME__: compilation time is like "22:00:00"
Code:
Char BuildFile [] = _ _ FILE__; int BuildLine = _ _ LINE__; char BuildDate [] = _ _ DATE__; char BuildTime [] = _ _ TIME__; printf ("compile file path:% s\ n", BuildFile); printf ("compiled code line:% d\ n", TestLine); printf ("compile date:% s\ n", BuildDate); printf ("compile time:% s\ n", BuildTime)
Hint: _ _ LINE__ is integer data
In fact, apart from these, there are many related definitions, such as:
1. Function constant pointer: function name, type: character constant pointer.
Char const* BuildFunName = _ _ FUNCTION__; printf ("function name:% s\ n", BuildFunName)
2.__VER__:IDE version information, type: integer.
For example, the IAR version I use is 7.80.04, as shown below:
Code:
Int IDEVersion = _ _ VER__; printf ("IDE version:% d\ n", IDEVersion)
Output:
IDE version: 7080004
Second, variable parameters
When we learn the C language, we all know that printf is a function with variable arguments:
Char a = 1; char b = 2; char c = 3; printf ("a =% d\ n", a); printf ("a =% d; b =% d\ n", a, b); printf ("a =% d; b =% d; c =% d\ n", a, b, c)
The above is an example of a variable parameter printf, which means that there can be one or more parameters.
Next, _ _ VA_ARGS__, is a variable parameter macro, which is the same as the macro definition of variable parameters in printf, which is added in the new C99 specification.
1. About _ _ VA_ARGS__
_ _ VA_ARGS__ it is a variable parameter macro, that is, put the left macro in "." Is copied as is in the location of _ _ VA_ARGS__ on the right.
It should be noted that the output format of printf is a string on the left and variables on the right in parentheses, and the right variable corresponds to the left output format one by one. As you can see in the following example, _ _ VA_ARGS__ actually follows the format of printf.
... The default number represents a table of parameters that can be changed. Use the reserved name _ _ VA_ARGS__ to pass parameters to the macro. When the macro call expands, the actual parameters are passed to printf ().
two。 Example illustration
# define SENSOR_Printf (...) Printf ("- SENSOR--" _ _ VA_ARGS__) int TemperatureVal = 25; SENSOR_Printf ("temperature =% d ℃\ n", TemperatureVal)
Output result:
-- SENSOR-- temperature = 25 ℃
A dedicated friend may guess: "." Similar equals "_ _ VA_ARGS__".
We can see from the example that the purpose of _ _ VA_ARGS__ is mainly for functions with variable parameters. We use a lot of printf is the most common one.
If our project is very large, we can classify the printed information, and this advantage is that it is convenient for us to identify all kinds of printed information.
After reading this, the article "what are the special standards defined and used in C language" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it before you can understand it. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.