fork(1) download
  1. #include <stdio.h>
  2.  
  3. int ic, cd, dc, ci;
  4.  
  5. void prepare(int n, char chd, double d, char chi, int i)
  6. {
  7. printf("%p\n%p\n%p\n%p\n%p\n", &n, &chd, &d, &chi, &i);
  8.  
  9. ic = (char*)&chd - (char*)&n;
  10. cd = (char*)&d - (char*)&chd;
  11. dc = (char*)&chi - (char*)&d;
  12. ci = (char*)&i - (char*)&chi;
  13. }
  14.  
  15. double sum(int n, ...)
  16. {
  17. printf("%d\n", n);
  18.  
  19. if (!ic)
  20. {
  21. prepare(0, '0', 0., '0', 0);
  22. printf("%d %d %d %d\n", ic, cd, dc, ci);
  23. fflush(stdout);
  24. }
  25.  
  26. char *p = (char*)&n + ic;
  27. double sum = 0;
  28.  
  29. while (n--)
  30. switch (*p)
  31. {
  32. case 'i':
  33. // printf("%d\n", *(int*)(p += ci));
  34. sum += *(int*)(p += ci);
  35. p += ic;
  36. break;
  37.  
  38. case 'd':
  39. sum += *(double*)(p += cd);
  40. p += dc;
  41. break;
  42.  
  43. default:
  44. fputs(stderr, "Invalid type");
  45. return sum;
  46. }
  47.  
  48. return sum;
  49. }
  50.  
  51. int main(void)
  52. {
  53. double x = sum(6, 'i', 1, 'd', 2., 'i', 3, 'd', 4., 'i', 5, 'd', 6.);
  54. printf("%f\n", x);
  55. return 0;
  56. }
Runtime error #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
6
0x7ffeebd3cf88
0x7ffeebd3cf86
0x7ffeebd3cf90
0x7ffeebd3cf87
0x7ffeebd3cf8c
-2 10 -9 5