fork download
  1. #include <stdio.h>
  2.  
  3. void func1(void);
  4. void func2(void);
  5.  
  6. //#define func1(...) func1##__VA_ARGS__()
  7. //#define func2(...) func2##__VA_ARGS__()
  8. //#define func1 func1void
  9. //#define func2 func2void
  10. #define func1(x) func1void
  11. #define func2(...) func2##__VA_ARGS__()
  12.  
  13. // --- 既存ソース部分。実際には#includeで取り込む ---
  14. static void test(void)
  15. {
  16. func1(10);
  17. func2();
  18. }
  19.  
  20. void func1(int a)
  21. {
  22. printf("func1()\n");
  23. }
  24. void func2(void)
  25. {
  26. printf("func2()\n");
  27. }
  28. // --- 既存ソース終わり ---
  29.  
  30. #undef func1
  31. #undef func2
  32.  
  33. void func1(int a)
  34. {
  35. printf("func1_stub()\n");
  36. }
  37. void func2(void)
  38. {
  39. printf("func2_stub()\n");
  40. }
  41.  
  42. int main()
  43. {
  44. test();
  45. return 0;
  46. }
Compilation error #stdin compilation error #stdout 0s 2112KB
stdin
Standard input is empty
compilation info
prog.c: In function 'test':
prog.c:10:21: error: 'func1void' undeclared (first use in this function)
 #define func1(x)    func1void
                     ^
prog.c:16:5: note: in expansion of macro 'func1'
     func1(10);
     ^
prog.c:10:21: note: each undeclared identifier is reported only once for each function it appears in
 #define func1(x)    func1void
                     ^
prog.c:16:5: note: in expansion of macro 'func1'
     func1(10);
     ^
prog.c: At top level:
prog.c:21:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
 {
 ^
prog.c:33:6: error: conflicting types for 'func1'
 void func1(int a)
      ^
prog.c:3:6: note: previous declaration of 'func1' was here
 void func1(void);
      ^
stdout
Standard output is empty