Current location - Training Enrollment Network - Mathematics courses - Why use standard library functions instead of writing them yourself?
Why use standard library functions instead of writing them yourself?
Standard library functions have three advantages: accuracy, efficiency and portability.

Accuracy: Compiler developers usually guarantee the accuracy of standard library functions. More importantly. At least the developer has done a comprehensive test to confirm its accuracy, which is more comprehensive than you can do (some expensive testing tools can make this work easier).

Efficiency: Excellent C programmers will use a lot of standard library functions, and expert compiler developers also know this. If the developer can provide an excellent set of standard library functions, he will have an advantage in the competition. A set of excellent standard library functions will play a decisive role in comparing the efficiency of competitive compilers. So developers are more motivated and have more time to develop a set of efficient standard library functions than you.

Portability: In the case of changing software requirements, standard library functions have the same function and express the same meaning for any compiler on any computer, so it is one of the few reliance of C programmers.

Interestingly, it is difficult to find the most standard information about standard library functions. For each function, you need one (in rare cases, two) header file to ensure that the prototype of the function can be provided to you (when calling any function, you should include its prototype, see 8.2). What's the fun? This header file may not really contain the prototype of this function, but in some cases (very bad! ), even the header files recommended by the compiler manual are not necessarily correct. This can also happen to macro definitions, typedef, and global variables.

In order to find the "correct" header file, you can look up the corresponding function in the copy of ANSI/ISO c standard.