fork download
  1. /* cpp2c.c
  2.  * Translate C++ http://i...content-available-to-author-only...e.com/vAp2Sj to C language program.
  3.  * https://m...content-available-to-author-only...h.net/test/read.cgi/tech/1554171817/630
  4.  * Copyright (C) 2019 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>.
  5.  * This file is public domain software.
  6.  */
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9.  
  10. typedef struct A
  11. {
  12. int a;
  13. } A;
  14.  
  15. void A_A(A *This, int a)
  16. {
  17. This->a = a;
  18. }
  19.  
  20. void A_f(A *This)
  21. {
  22. printf("a = %d\n", This->a);
  23. }
  24.  
  25. typedef struct B
  26. {
  27. int b;
  28. } B;
  29.  
  30. void B_B(B *This, int b)
  31. {
  32. This->b = b;
  33. }
  34.  
  35. void B_g(B *This)
  36. {
  37. printf("b = %d\n", This->b);
  38. }
  39.  
  40. typedef struct C
  41. {
  42. A ThisA;
  43. B ThisB;
  44. int c;
  45. } C;
  46.  
  47. void C_C(C *This, int a, int b, int c)
  48. {
  49. A_A(&This->ThisA, a);
  50. B_B(&This->ThisB, b);
  51. This->c = c;
  52. };
  53.  
  54. void C_h(C *This)
  55. {
  56. A_f(&This->ThisA);
  57. B_g(&This->ThisB);
  58. printf("c = %d\n", This->c);
  59. }
  60.  
  61. C *C_new(int a, int b, int c)
  62. {
  63. C *This = (C *)malloc(sizeof(C));
  64. C_C(This, a, b, c);
  65. return This;
  66. }
  67.  
  68. void C_delete(C *This)
  69. {
  70. free(This);
  71. }
  72.  
  73. int main(void)
  74. {
  75. C *c = C_new(5, 6, 7);
  76. A_f(&c->ThisA);
  77. B_g(&c->ThisB);
  78. C_h(c);
  79. C_delete(c);
  80. return 0;
  81. }
  82.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
a = 5
b = 6
a = 5
b = 6
c = 7