In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "JavaScript conditional compilation application case analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Conditional compilation instructions are mainly used to determine which code in the program can be compiled and which is not compiled. The commands commonly used in conditional compilation are: 1, # if # else and # endif compilation command groups; 2, # ifdef # undef and # endif compilation command groups; 3, # ifndef # define and # endif compilation command groups.
Specifically, it is:
(1)
# if expression
Code segment
# endif
If the expression is true, the following code is compiled, otherwise it is not compiled.
# endif is the end of the # if preprocessing instruction and cannot be omitted.
Setting the expression to 0 can serve as a comment on the code.
(2)
# if expression
Code snippet 1
# else
Code snippet 2
# endif
If the expression is true, snippet 1 is compiled and executed, otherwise snippet 2 is executed.
Program case:
/ *
Objective: to design a compiler switch, which controls the execution of the program by compiling the switch. If the switch is turned on, it will
Lowercase letters in known strings are converted to uppercase letters, otherwise uppercase letters are converted to lowercase letters.
, /
# include
# define LEN 100
# define LOWERCASE 1
Int main ()
{
Char str [LEN]
Char c
Int I = 0
Printf ("Enter a string:\ n")
Gets (str)
While ((c = str [I])! ='\ 0') / / traversal string
{
I + +
# if LOWERCASE
If (c > ='A'& & c ='a'& & c ='a'& & telegram [I] ='Z'& & telegram [I] <'Z'))
{
Telegram [I] + = 1; / / becomes the next letter
}
Else if (('z' = = telegram [I]) | ('Z' = = telegram [I]))
{
Telegram [I]-= 25
}
}
Printf ("Telegraph password message:")
Puts (telegram)
Printf ("\ n")
# else
Printf ("Telegraph message:")
Puts (telegram)
Printf ("\ n")
# endif
Return 0
}
/ *
The output in Code::Blocks is as follows:
Please enter a telegram message:
Abcdefghijklmnopqrstuvwxyz
The telegram password message is: bcdefghijklmnopqrstuvwxyza
, /
(4)
# ifndef Macro name
Code snippet 1
# else
Code snippet 2
# endif
The macro name can be any defined or undefined macro. If the program has never defined a macro before, compile and execute snippet 1, otherwise compile and execute snippet 2.
This is the end of the content of "JavaScript conditional compilation Application example Analysis". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.