DLL export C-style function traps under namespaces

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.