fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. struct cdecl_tag { typedef void ( __attribute__((cdecl)) *type)(); };
  5. struct stdcall_tag { typedef void ( __attribute__((stdcall)) *type)(); };
  6. struct fastcall_tag { typedef void ( __attribute__((fastcall)) *type)(); };
  7.  
  8. constexpr void get_func_calling_convention_tag () {};
  9.  
  10. template<typename R, typename... Args>
  11. constexpr cdecl_tag
  12. get_func_calling_convention_tag (R (__attribute__((cdecl)) *)(Args...))
  13. { return {}; }
  14.  
  15. template<typename R, typename... Args>
  16. constexpr stdcall_tag
  17. get_func_calling_convention_tag (R (__attribute__((stdcall)) *)(Args...))
  18. { return {}; }
  19.  
  20. template<typename R, typename... Args>
  21. constexpr fastcall_tag
  22. get_func_calling_convention_tag (R (__attribute__((fastcall)) *)(Args...))
  23. { return {}; }
  24.  
  25. #define CALLING_CONVENTION_TAG(func) \
  26. decltype(get_func_calling_convention_tag(&func))
  27.  
  28. int __attribute__((cdecl)) foo (char) { return 0; }
  29. long __attribute__((stdcall)) bar (int) { return 0; }
  30.  
  31. int main()
  32. {
  33. std::cout << std::is_same<CALLING_CONVENTION_TAG(foo),
  34. cdecl_tag>::value << '\n'
  35. << std::is_same<CALLING_CONVENTION_TAG(bar),
  36. stdcall_tag>::value << '\n'
  37. << std::is_same<CALLING_CONVENTION_TAG(foo),
  38. CALLING_CONVENTION_TAG(bar)>::value << std::endl;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1
1
0