functions.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2024 Gtker
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. typedef void (*FUNCTION)(void);
  18. typedef int (*MyFunction)(int, int);
  19. typedef int (*MyFunctionArgs)(int first_arg, int second_arg);
  20. typedef int (*MyFunc)(int*, int**);
  21. typedef int (*MyFuncArgs)(int* first_arg, int** second_arg);
  22. typedef int (*MyFuncFp)(int* first_arg, int** second_arg, void(*third_arg)(void), void(*)(void));
  23. static int a;
  24. static int add_static(int a) { return a + a; }
  25. inline int add_inline(int c) { return c + c; }
  26. static inline int add_both(int x) { return x + x; }
  27. inline static int add_reversed(int b) { return b + b; }
  28. _Noreturn void do_not_return();
  29. void (*global_function_pointer)(void);
  30. void (*global_int_fp)(int, int);
  31. void (*global_pointer_fp)(int*, int*);
  32. void (*global_int_name_fp)(int first_arg, int second_arg);
  33. void (*global_pointer_name_fp)(int* first_arg, int* second_arg);
  34. void (*global_pointer_fp_fp)(int* first_arg, int* second_arg, void (*third_arg)(void), void (*)(void));
  35. struct {
  36. void (*f)(void);
  37. void (*f_int)(int, int);
  38. void (*f_pointer)(int*, int*);
  39. void (*f_name_int)(int first_arg, int second_arg);
  40. void (*f_pointer_name)(int* first_arg, int* second_arg);
  41. void (*f_pointer_fp)(int* first_arg, int* second_arg, void (*third_arg)(void), void (*)(void));
  42. };
  43. int array_arg(char arg[]) { return sizeof(arg); }
  44. int array_arg2(char arg[][]) { return sizeof(arg); }
  45. int array_arg3(char* arg[]) { return sizeof(arg); }
  46. int array_arg4(char* arg[][]) { return sizeof(arg); }
  47. int array_arg5(char arg[10 + 10]) { return sizeof(arg); }
  48. int array_arg6(char* arg[10 + 10]) { return sizeof(arg); }
  49. int array_arg7(char* arg[10 + 10][8 + 1]) { return sizeof(arg); }
  50. int array_arg8(char arg[10 + 10][8 + 1]) { return sizeof(arg); }
  51. int main() {
  52. a = 1;
  53. if(2 != add_static(1)) return 1;
  54. if(2 != add_both(1)) return 2;
  55. if(2 != add_reversed(1)) return 3;
  56. if(2 != add_inline(1)) return 4;
  57. if(a != 1) return 5;
  58. MyFunction my_function;
  59. MyFunc my_func;
  60. MyFuncArgs my_func_args;
  61. MyFunctionArgs my_function_args;
  62. MyFuncFp my_func_fp;
  63. void (*function_pointer)(void);
  64. void (*int_fp)(int, int);
  65. void (*pointer_fp)(int*, int*);
  66. void (*int_name_fp)(int first_arg, int second_arg);
  67. void (*pointer_name_fp)(int* first_arg, int* second_arg);
  68. void (*pointer_fp_fp)(int* first_arg, int* second_arg, void (*third_arg)(void), void (*)(void));
  69. if(array_arg(0) != sizeof(char*)) return 6;
  70. if(array_arg2(0) != sizeof(char**)) return 7;
  71. if(array_arg3(0) != sizeof(char**)) return 8;
  72. if(array_arg4(0) != sizeof(char***)) return 9;
  73. if(array_arg5(0) != sizeof(char*)) return 10;
  74. if(array_arg6(0) != sizeof(char**)) return 11;
  75. if(array_arg7(0) != sizeof(char***)) return 12;
  76. if(array_arg8(0) != sizeof(char**)) return 13;
  77. return 0;
  78. }