fork(3) download
  1. #include <iostream>
  2. #include <cstdarg>
  3.  
  4. using namespace std;
  5.  
  6. extern "C"
  7. int accumulateFunction (int count, ...)
  8. {
  9. int res = 0;
  10. va_list args;
  11. va_start(args, count);
  12. for (int i = 0; i < count; ++i)
  13. res += va_arg(args, int);
  14.  
  15. va_end(args);
  16. return res;
  17. }
  18.  
  19. int accumulate3Function (int fst, int snd, int thd)
  20. {
  21. return fst + snd + thd;
  22. };
  23.  
  24.  
  25.  
  26. typedef int (*sum3Function)(int, int, int);
  27.  
  28. int main()
  29. {
  30. sum3Function sum;
  31.  
  32. sum = accumulate3Function;
  33. std::cout << sum (2,3,4) << std::endl;
  34.  
  35. sum = reinterpret_cast<sum3Function>(accumulateFunction);
  36. std::cout << sum (2,3,4) << std::endl;
  37.  
  38. return 0;
  39. };
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
9
7