1, compile stage, if not overloaded, then C-style function with the same name and C + + style of the same name, will be reported compilation error.
Error c2084:function ' int Test (void) ' already has a body.
2. During compilation, the compiler checks the functions in the namespace. such as Sg::test ();
The compiler detects if there is a function test () in the SG namespace. If not, you will get an error.
Error C2039: ' Test ': is not a member of ' SG '
3, link stage, when the namespace is combined with extern "C", the generated function code is actually C-style, there is no namespace decoration.
This is because there is no concept of namespaces in C-style functions, so namespaces are automatically ignored by the linker.
Based on the above principles, the compiler linker is able to identify all the basic error usages.
However, there is a case where the compiler linker is not recognized.
That's
There are namespaces in Dlla
{"C" __declspec(dllexportint Test()}
There is a namespace sg2::test () export function in DLLB.
{"C" __declspec(dllexportvoid Test()}
Call Sg2::test () in the EXE. At this point, the compile link is correct. But the actual operation of the time, but there is a hidden danger. Because the actual generated assembly code is directly
Call (781a18h)
is not associated with a namespace. So does the assembly code call test under SG1 or SG2? These two DLLs who first reference into the EXE, first call who.
DLL export C-style function traps under namespaces