C诡异bug测试连载_1 (测试框架)

下面程序用于测试C语言的一些诡异特性, 今天我自己写了一个测试框架,以后连载只提供测试函数.

测试函数编写方法:
  1. TEST_FUN(
  2.      fun_name,
  3.      fun_description_str
  4.  )
  5. {
  6.      ...
  7. }
测试函数调用方法:
  1. RUN_TEST(fun_name);

测试框架源代码(包含一个测试样例)
  1. /*
  2.     Author   : Anders Ma
  3.     Function : To show C language tricky feature
  4.     Since 2008_1008
  5. */
  6. #include <stdio.h>

  7. #define TEST_FUN(name, function) /
  8.     char* name##_fun_str = function; /
  9.     void name()
  10. #define RUN_TEST(name) /
  11.     printf("Test     : %s/nFunction : %s/n", #name, name##_fun_str); /
  12.     printf("--------------/n"); /
  13.     name();

  14. TEST_FUN(
  15.     test_1,
  16.     "auto type conversion -- int variable is converted to 'unsigned int'"
  17. )
  18. {
  19.     int i = -2;
  20.     unsigned int j = 5;
  21.     if (i < j)
  22.         printf("int i=%d;/nunsigned int j=%d;/ni < j/n", i, j);
  23.     else if (i > j)
  24.         printf("int i=%d;/nunsigned int j=%d;/ni > j/n", i, j);
  25. }

  26. int main ()
  27. {
  28.     RUN_TEST(test_1);
  29.     return 0;
  30. }

  31. --------------
  32. test_1测试结果:
  33. --------------
  34. Test     : test_1
  35. Function : auto type conversion -- int variable is converted to 'unsigned int'
  36. --------------
  37. int i=-2;
  38. unsigned int j=5;
  39. i > j



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值