In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of what are the function design principles that are easy to be ignored in C language, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on function design principles that are easy to be ignored in C language. Let's take a look at it.
Principle of function design
Function should be an independent functional module in a sense.
The function name should reflect the function of the function to some extent.
The function parameter name should be able to reflect the meaning of the parameter.
Try to avoid using global variables in functions
When function parameters should not be modified within the function body, a const declaration should be added
If the parameter is a pointer and is used only as an input parameter, the const declaration should be added as follows:
The type of return value cannot be omitted
If the function does not return a value, it should be declared as void
Type to check the validity of parameters
It is particularly important to check pointer parameters.
Do not return a pointer to Stack memory
The function body in the stack is automatically released at the end of the stack.
The size of the function body should be small and be controlled within 80 lines of code as much as possible.
The same input corresponds to the same output, avoiding the function with "memory" function.
Avoid having too many parameters in the function, and try to control the number of parameters within 4.
Sometimes functions do not need return values, but to increase flexibility, such as supporting chained expressions, return values can be attached
There is no semantic conflict between the function name and the return value type.
Ver2 * / int versionCmp (char* ver1, char* ver2) {char* dot1; char* dot2; int num1; int num2; dot1 = strchr (ver1,'.'); dot2 = strchr (ver2,'.'); num1 = atoi (ver1); num2 = atoi (ver2); if (num1 > num2) return 1; if (num1
< num2) return -1; if (dot1 && !dot2) /* x.y >X * / return 1; if (! dot1 & & dot2) / * x < x.y * / return-1; if (! dot1 & &! dot2) / * x = = x * / return 0; return versionCmp ((char*) (dot1 + 1), (char*) (dot2 + 1)) } # endif / * AIX * / this is the end of the article on "what are the function design principles that are easy to be ignored in C language". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what are the function design principles that are easy to be ignored in C language". If you want to learn more knowledge, you are 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.