In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the naming rule in C language". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the naming rule in C language"?
I. Common naming rules
The more famous naming rule is the Hungarian nomenclature. This naming method was proposed by Microsoft programmer Charles Simone (CharlesSimonyi). The main idea is to add prefixes to variables and function names to improve people's understanding of the program. The key to Hungarian naming is that the name of an identifier begins with one or more lowercase letters as a prefix; the prefix is followed by an uppercase word or combinations of words that indicate the purpose of the variable. For example: lpszStr, which represents a long pointer (1p) variable to a string that ends with'\ 0' (sz).
Camel nomenclature is a more and more popular nomenclature in recent years. It is well used in many new function libraries and Java platforms. Camel nomenclature, as its name suggests, refers to names that mix uppercase and lowercase letters to form identifiers. The first letter of the first word is lowercase and the rest is capitalized. For example: printEmployeePaychecks (), each logical breakpoint in the function name is marked with an uppercase letter.
Pascal nomenclature is similar to camel nomenclature, except that camel nomenclature is lowercase of the first word, while Pascal naming rules are capitalization of the first word. For example, DisplayInfo () and UserName both use Pascal naming.
In C language, Pascal nomenclature and camel nomenclature are the most common. In fact, many programmers combine camel naming with Pascal in actual naming, such as camel naming for variable names and Pascal naming for functions.
Another popular naming convention is called underscore naming. Underlining has become popular with the advent of the C language, and it is widely used in environments like UNIX/LIUNX and in GNU code. The naming rules described in this paper are mainly based on underscore nomenclature.
Second, the naming of the function
Function names are named using underscores to split lowercase letters, such as:
Device name _ operation name 0
The operation name generally takes the form of predicate (when the device name is used as the object or indicates the module to which the operation belongs) or predicate object / predicate (when the device name is used as the subject or indicates the module to which the operation belongs), such as:
Tic_init ()
Adc_is_busy ()
Uarttxchar ()
The interrupt function is named directly in the form of the device name _ isr (), such as:
Timer2_isr ()
Third, the naming of variables
Variables are also named by underscores dividing lowercase letters. The naming should be accurate, not ambiguous, and of moderate length. Such as:
Intlength
Uint32testoffset
Single-character names are also commonly used, such as I, j, k, etc., which can usually be used as local variables within a function.
T01384f9202887f15b8.jpg?size=540x252 big picture mode
Variable names are often used for affectation in tmp.
For local static variables, add the prefix s _ (for static), such as:
Staticints_lastw
For global variables (especially those for external access), add the g prefix (for global), such as:
Void (* g_capture_hook) (void)
IV. Naming of constants and macros
The underscore is used to divide uppercase letters, and the device name should be used as a prefix to prevent repetition of naming between modules. Such as:
# defineTIMER0_MODE_RELOAD2
# defineTIMER2_COUNT_RE-TRIEVE (val) ((uintl6) (65536 _ (val)
Of course, macros that are treated as interfaces can be named after the naming method of the function, for example:
# definetimer2_clearo (TF2=0)
# definetimer0isexpiredO (TF0)
Commonly used acronyms
In fact, there is no naming convention that all programmers can agree with. And these naming rules do have their own advantages and disadvantages. There is no need to spend too much effort trying to invent the best naming rules, but should develop a naming convention that is satisfactory to most project members and implement it. The consistency of identifier naming naturally reflects the elegance of the code. Of course, if your program uses third-party code, and these modules have been verified to be correct, then there is no need to blindly pursue naming consistency and modify the names of functions and variables in these stereotyped modules.
At this point, I believe you have a deeper understanding of "what is the naming rule in C language". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.