dubious.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // The { coming up should be on its own line.
  2. int
  3. foo(void) {
  4. // There should be a space before (1)
  5. if(1) x += 1;
  6. // The following empty line is unnecessary.
  7. }
  8. // There should be a newline between void and bar.
  9. void bar(void)
  10. {
  11. // too wide:
  12. testing("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  13. }
  14. long
  15. bad_spacing()
  16. {
  17. // here comes a tab
  18. return 2;
  19. // here comes a label without space:
  20. foo:
  21. ;
  22. }
  23. // Here comes a CR:
  24. // Trailing space:
  25. int
  26. non_k_and_r(void)
  27. {
  28. // non-k&r
  29. if (foo)
  30. {
  31. // double-semi
  32. return 1;;
  33. }
  34. else
  35. {
  36. return 2;
  37. }
  38. }
  39. // #else #if causes a warning.
  40. #if 1
  41. #else
  42. #if 2
  43. #else
  44. #endif
  45. #endif
  46. // always space before a brace.
  47. foo{
  48. }
  49. void
  50. unexpected_space(void)
  51. {
  52. // This space gives a warning.
  53. foobar (77);
  54. }
  55. void
  56. bad_function_calls(long)
  57. {
  58. // These are forbidden:
  59. assert(1);
  60. memcmp("a","b",1);
  61. strcat(foo,x);
  62. strcpy(foo,y);
  63. sprintf(foo,"x");
  64. malloc(7);
  65. free(p);
  66. realloc(p);
  67. strdup(s);
  68. strndup(s,10);
  69. calloc(a,b);
  70. }