C++ linker presentation
This commit is contained in:
33
cpplinker/03_name_mangling/mangling.cpp
Normal file
33
cpplinker/03_name_mangling/mangling.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
|
||||
int process(int x) { return x * 2; }
|
||||
int process(double x) { return (int)(x * 2); }
|
||||
int process(int x, double y) { return x + (int)y; }
|
||||
|
||||
namespace Math {
|
||||
double sqrt(double x) { return x * 0.5; }
|
||||
}
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
double x, y;
|
||||
double dot(const Vector& v) { return x * v.x + y * v.y; }
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
int legacy_init(void) { return 0; }
|
||||
void legacy_free(void* p) { (void)p; }
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "process(3) = " << process(3) << "\n";
|
||||
std::cout << "process(3.0) = " << process(3.0) << "\n";
|
||||
std::cout << "process(3, 4.0) = " << process(3, 4.0) << "\n";
|
||||
std::cout << "Math::sqrt(9) = " << Math::sqrt(9.0) << "\n";
|
||||
|
||||
Vector a{1, 2}, b{3, 4};
|
||||
std::cout << "a.dot(b) = " << a.dot(b) << "\n";
|
||||
|
||||
std::cout << "legacy_init() = " << legacy_init() << "\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user