Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- extern "C" {
- static int do_stuff(int) {
- return 3;
- }
- template <typename return_t_, typename arg1_t_>
- struct test {
- static void foo(return_t_ (*)(arg1_t_)) { }
- };
- }
- int main()
- {
- test<int, int>::foo(&do_stuff);
- return EXIT_SUCCESS;
- }
- #include <cstdlib>
- extern "C" {
- static int do_stuff(int) {
- return 3;
- }
- struct test {
- static void foo(int (*)(int)) { }
- };
- }
- int main()
- {
- test::foo(&do_stuff);
- return EXIT_SUCCESS;
- }
- extern "C" {
- class X {
- void mf(); // the name of the function mf and the member
- // function's type have C++ language linkage
- void mf2(void(*)()); // the name of the function mf2 has C++ language
- // linkage; the parameter has type pointer to C function
- };
- }
- void f() {
- struct S {};
- vector<S> v; // Not allowed as S has internal linkage.
- }
- void f() {
- // Not allowed:
- template<class T>
- struct S {};
- }
- #include <cassert>
- template <class C>
- C f(C i) { return i; }
- int main() {
- f<int>(1);
- f<double>(1.5);
- }
- g++ -c -g -std=c++98 main.cpp
- objdump -Sr main.o
- int main() {
- 0: 55 push %rbp
- 1: 48 89 e5 mov %rsp,%rbp
- 4: 48 83 ec 10 sub $0x10,%rsp
- f<int>(1);
- 8: bf 01 00 00 00 mov $0x1,%edi
- d: e8 00 00 00 00 callq 12 <main+0x12>
- e: R_X86_64_PC32 _Z1fIiET_S0_-0x4
- f<double>(1.5);
- 12: 48 b8 00 00 00 00 00 movabs $0x3ff8000000000000,%rax
- 19: 00 f8 3f
- 1c: 48 89 45 f8 mov %rax,-0x8(%rbp)
- 20: f2 0f 10 45 f8 movsd -0x8(%rbp),%xmm0
- 25: e8 00 00 00 00 callq 2a <main+0x2a>
- 26: R_X86_64_PC32 _Z1fIdET_S0_-0x4
- }
- 2a: b8 00 00 00 00 mov $0x0,%eax
- 2f: c9 leaveq
- 30: c3 retq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement