Understanding the Design Vulnerabilities of the C Language: Why is function overloading not allowed?

  1. In the C language, even if the return type is not written, the program can be compiled and run. Because the function of C language only looks at the name, not the return type. When looking for the entry function, the program only needs to find the function named "main", and does not care about the return type and parameter type.

  2. The C language does not allow function overloading. The function with the same name only has different parameters. The C language regards it as a duplicate function symbol.

  3. In C language, the caller clears the stack, so it can be declared as void type in the main function even if no parameters are written, the program will not go wrong, but the command line parameters cannot be obtained.

  4. At the assembly level, the value returned by the function is the value of the EAX register. If no value is assigned, the EAX register is a random number. Therefore, even if it is declared as void type, the main function also has a return value, which is just a random value.

  5. The design of the C language has some inaccuracies, some of which are left over from the early compilers, so the code should be written according to the modern C language specification to improve readability and maintainability.

  6. Although the return value of the main function may have no practical meaning in the code, it still has a role. In the Unix system, a process is called as a function. After starting a child process, it is necessary to use the return value of the process to obtain the status of whether the child process is running correctly. Therefore, the return value of the main function will be returned to the parent process as the status code of the end of the process.


    e4d1c98c8b84b362b1d0336ecfa02ae8.jpegIt just so happens that I have a C language package here, private message me to get it

Guess you like

Origin blog.csdn.net/m0_67034740/article/details/129730107