名称混淆和在C++概念中使用”extern C”
我们知道C++编程语言非常强大,并且被广泛应用于游戏开发行业。它支持函数重载的功能,即可以使用不同的参数定义同名函数,编译器可以将它们映射为不同的实体。
相反,参数是不同的,但函数名是相同的。在这种情况下,我们使用名称混淆的方法来映射具有相同名称的函数,使编译器将它们理解为不同的对象。该方法向任务添加额外的信息,这些信息将有所不同。因此,本地或在线编译器可以在没有混淆的情况下运行它们。
C++代码
// here we are writing down the tiny code snippet to demonstrate the
// concept of Name Mangling and extern "C" in C++, function overloading in C++
// programming language and name mangling concept
int v(void) { return 1; }
// this is a sample integer variable declared with a return type 0.
int v(int) { return 0; }
// A simple void function holding integer variables i and j.
void hh(void) { int i = v(), j = v(0); }
// end of the Name Mangling and extern "C" in C++ concept partial
// demonstration
输出:
G ++ / t m p/F mT y bF gU rL. cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned one exit status
C++代码
// here we are writing down the tiny code snippet to demonstrate the
// concept of Name Mangling and extern "C" in C++, function overloading in C++
// programming language and name mangling concept
// this is a sample integer variable declared with a return type 1.
int __f_v(void) { return 1; }
// this is a sample integer variable declared with a return type 1.
int __f_i(int) { return 0; }
// A simple void function holding integer variables i and j.
void __g_v(void) { int i = __f_v(), j = __f_i(0); }
// end of the Name Mangling and extern "C" in C++ concept partial
// demonstration
输出:
G ++ / t m p/F mT y bF gU rL. cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status
C++代码
// here we are writing down the tiny code snippet to demonstrate the
// concept of Name Mangling and extern "C" in C++, function overloading in C++
// programming language and name mangling concept
int printf(const char* format, ...);
// the main driver code functionality starts from here
int main()
{
// A simple printf function holding the display statement javaTpoint.com
printf("javaTpoint.com");
return 0;
}
// end of the Name Mangling and extern "C" in C++ concept partial
// demonstration
输出:
g++ /tmp/FmTybFgUrL.cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status
在C++编程语言中的Extern “C”
C++代码
// here we are writing down the tiny code snippet to demonstrate the
// concept of Name Mangling and extern "C" in C++, function overloading in C++
// programming language and name mangling concept
extern "C" {
int printf(const char* format, ...);
}
// the main driver code functionality starts from here
int main()
{
// A simple printf function holding the display statement javaTpoint.com
printf("javaTpoint.com");
return 0;
}
// end of the Name Mangling and extern "C" in C++ concept partial
// demonstration
输出:
G ++ / t m p/F mT y bF gU rL. cpp
javaTpoint.com
stdio.h、string.h文件中的C语言声明
C++代码
// here we are writing down the tiny code snippet to demonstrate the
// concept of Name Mangling and extern "C" in C++, function overloading in C++
// programming language and name mangling concept
#ifdef __cplusplus
extern "C" {
#endif
// Declarations of this file
// this below small code helps us with declarations of the file
#ifdef __cplusplus
}
#endif
// end of the Name Mangling and extern "C" in C++ concept partial
// demonstration
输出:
G ++ / t m p/F mT y bF gU rL. cpp
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: error: ld returned 1 exit status