Is there any type checking in C or C++ linkers? -


Am I right that the linkers do not make a function parameter check, do not check the number or type of function calls Nor do they check the type of global data references. Is this true for all links?

I am using Clegg to target Linux on x86-64. Does the connector check that the references are in the correct section? Or in what effect is an external reference just a zero *, as far as Linker is concerned?

I am coming from a high level language background, C # and Scala, so it can be clear to those who are submerged in the low level world, I have some of my work in assembler System call) and I saw that the assembler had no parameter prototype for the external function.

References: I am actually writing a compiler, I am currently targeting preprocessed C.I files with system for caller call, but option C ++, assembler or even That's machine code, so I'm trying to check the weight of the cost and benefits, especially the type of code / compiler / linker I have the correctness of my own program and its function prototype generation You can use it to see. As explained in the form of

, the functions can be overloaded based on their criteria, and therefore the compiler The mangled function prepares names that contain information about parameters and their type. Linker mainly checks the name and size of the symbol only, but since mangling ensures that the names of the functions are different, the mismatched parameters will not link.

The function is not part of the return type Mangling (because overloading is not legal on the return type), so if you type in a code int test () Announce and call float test () in the second, the links will not be able to catch it, and you will get bad results.

Similarly, the types of global variables (and static members of classes and so on) are not checked by the linker, so if you do extern int test; Declare in a translation unit and define float test; In the second, you will get bad results.

In Lynkar, in some circumstances, compare the size of the symbol in two different translation units and there may be some problems like this.

In practice, this is rarely an issue in normal C ++ development, because whenever a function or variable or class is required> 1 translation unit, you will declare it in a header file The translation units are included in both, and the compilers will catch any errors before the linker will also run. (An example where this could be an issue, if you are using external, binary library and your files do not match the Haemer Library.)


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -