Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Book review
- programming_book
- RFID
- ubuntu
- Java
- France
- Programming
- comic agile
- agile
- Kuala Lumpur
- hadoop
- Book
- QT
- Python
- web
- Malaysia
- MySQL
- Linux
- essay
- Software Engineering
- psychology
- erlang
- program
- history
- django
- leadership
- hbase
- Italy
- Spain
- management
Archives
- Today
- Total
C/C++ mixed programming 본문
출처: http://yesarang.tistory.com/65
naming mangling
naming mangling
// mixed.cpp #includeusing namespace std; double max(double a, double b) { cout << "double max(double, double) called" << endl; if (a > b) return a; else return b; } int max(int a, int b) { cout << "int max(int, int) called" << endl; if (a > b) return a; else return b; } int main(void) { double dm = max(23.7, 35.1); int im = max(10,5); cout << "double max = " << dm << endl << "int max = " << im << endl; } /* $ g++ mixed.cpp $ ./a.out double max(double, double) called int max(int, int) called double max = 35.1 int max = 10 $ g++ --version g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ nm ./a.out 0000000000600e10 d _DYNAMIC 0000000000600fe8 d _GLOBAL_OFFSET_TABLE_ 0000000000400a8f t _GLOBAL__I__Z3maxdd 0000000000400b98 R _IO_stdin_used w _Jv_RegisterClasses 0000000000400934 T _Z3maxdd 0000000000400988 T _Z3maxii 0000000000400a4f t _Z41__static_initialization_and_destruction_0ii */ // mixed.cpp #include using namespace std; double max(double a, double b) { cout << "double max(double, double) called" << endl; if (a > b) return a; else return b; } int max(int a, int b) { cout << "int max(int, int) called" << endl; if (a > b) return a; else return b; } namespace test { char max(char c1, char c2) { cout << "char test::max(char, char) called" << endl; if ( c1 > c2 ) return c1; else return c2; } }; using namespace test; int main(void) { double dm = max(23.7, 35.1); int im = max(10,5); char cm = max('a', 'z'); cout << "double max = " << dm << endl << "int max = " << im << endl << "char max = " << cm << endl; } /* $ g++ mixed.cpp $ ./a.out double max(double, double) called int max(int, int) called char test::max(char, char) called double max = 35.1 int max = 10 char max = z $ nm ./a.out | grep max 0000000000400b82 t _GLOBAL__I__Z3maxdd 00000000004009a4 T _Z3maxdd 00000000004009f8 T _Z3maxii 0000000000400a34 T _ZN4test3maxEcc */
Comments