Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <cstdlib>
  2.  
  3. extern "C" {
  4. static int do_stuff(int) {
  5. return 3;
  6. }
  7.  
  8. template <typename return_t_, typename arg1_t_>
  9. struct test {
  10. static void foo(return_t_ (*)(arg1_t_)) { }
  11. };
  12. }
  13.  
  14. int main()
  15. {
  16. test<int, int>::foo(&do_stuff);
  17. return EXIT_SUCCESS;
  18. }
  19.  
  20. #include <cstdlib>
  21.  
  22. extern "C" {
  23. static int do_stuff(int) {
  24. return 3;
  25. }
  26.  
  27. struct test {
  28. static void foo(int (*)(int)) { }
  29. };
  30. }
  31.  
  32. int main()
  33. {
  34. test::foo(&do_stuff);
  35. return EXIT_SUCCESS;
  36. }
  37.  
  38. extern "C" {
  39. class X {
  40. void mf(); // the name of the function mf and the member
  41. // function's type have C++ language linkage
  42. void mf2(void(*)()); // the name of the function mf2 has C++ language
  43. // linkage; the parameter has type pointer to C function
  44. };
  45. }
  46.  
  47. void f() {
  48. struct S {};
  49. vector<S> v; // Not allowed as S has internal linkage.
  50. }
  51.  
  52. void f() {
  53. // Not allowed:
  54. template<class T>
  55. struct S {};
  56. }
  57.  
  58. #include <cassert>
  59.  
  60. template <class C>
  61. C f(C i) { return i; }
  62.  
  63. int main() {
  64. f<int>(1);
  65. f<double>(1.5);
  66. }
  67.  
  68. g++ -c -g -std=c++98 main.cpp
  69. objdump -Sr main.o
  70.  
  71. int main() {
  72. 0: 55 push %rbp
  73. 1: 48 89 e5 mov %rsp,%rbp
  74. 4: 48 83 ec 10 sub $0x10,%rsp
  75. f<int>(1);
  76. 8: bf 01 00 00 00 mov $0x1,%edi
  77. d: e8 00 00 00 00 callq 12 <main+0x12>
  78. e: R_X86_64_PC32 _Z1fIiET_S0_-0x4
  79. f<double>(1.5);
  80. 12: 48 b8 00 00 00 00 00 movabs $0x3ff8000000000000,%rax
  81. 19: 00 f8 3f
  82. 1c: 48 89 45 f8 mov %rax,-0x8(%rbp)
  83. 20: f2 0f 10 45 f8 movsd -0x8(%rbp),%xmm0
  84. 25: e8 00 00 00 00 callq 2a <main+0x2a>
  85. 26: R_X86_64_PC32 _Z1fIdET_S0_-0x4
  86. }
  87. 2a: b8 00 00 00 00 mov $0x0,%eax
  88. 2f: c9 leaveq
  89. 30: c3 retq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement