1. Поиск говнокода

    Этот поиск практически ничего не может найти! Но вы всё-таки попытайтесь, вдруг повезет.

    Найдено: 35

  2. Python / Говнокод #28913

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    import sys
    
    
    def do_govno(govno: str) -> None:
        pass
    
    
    def main() -> int:
        if len(sys.argv) != 2:
            print(f'Usage: {sys.argv[0]} <govno>')
            return EXIT_FAILURE
        
        govno = sys.argv[1]
        do_govno(govno)
        
        return EXIT_SUCCESS
    
    
    if __name__ == '__main__':
        exit_code = main()
        sys.exit(exit_code)

    ISO, 13 Февраля 2024

    Комментарии (43)
  3. Си / Говнокод #27954

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
      int a[4] = {1, 2, 3, 4};
      int (*a_p1)[4] = (int (*)[4])a;
      int (*a_p2)[4] = &a;
      for(size_t i = 0; i < 4; ++i)
      {
        printf("%p -> %d; %p -> %d\n", &(*a_p1)[i], (*a_p1)[i], &(*a_p1)[i], (*a_p2)[i]);
      }
      return EXIT_SUCCESS;
    }

    Вот такой вывод:
    0x7ffee4ebd950 -> 1; 0x7ffee4ebd950 -> 1
    0x7ffee4ebd954 -> 2; 0x7ffee4ebd954 -> 2
    0x7ffee4ebd958 -> 3; 0x7ffee4ebd958 -> 3
    0x7ffee4ebd95c -> 4; 0x7ffee4ebd95c -> 4

    j123123, 14 Января 2022

    Комментарии (102)
  4. Си / Говнокод #27880

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <stdbool.h>
    
    struct two_val
    {
      const int32_t a[2];
    };
    
    struct two_val_and_status
    {
      const bool is_swap;
      const struct two_val t_v;
    };
    
    struct array
    {
      const int32_t a[10];
    };
    
    struct array_and_status
    {
      const bool is_swap;
      const size_t pos;
      const struct array arr;
    };
    
    // Эта суперфункцональная функция сортировки двух элементов не просто сортирует два элемента
    // но и еще сообщает о том, нужно ли было для этого обменивать два значения
    struct two_val_and_status sort2(const struct two_val a)
    {
      return (a.a[0] > a.a[1]) ? (struct two_val_and_status){true, {{a.a[1], a.a[0]}}} : (struct two_val_and_status){false, a};
    }
    
    struct two_val read_two_val(const struct array arr, const size_t pos)
    {
      return (struct two_val){{arr.a[pos], arr.a[pos+1]}};
    }
    
    struct array store_val(const struct array arr, const int32_t val, size_t pos)
    {
      return (struct array) // Царский анролл
      {{
        pos != 0 ? arr.a[0] : val,
        pos != 1 ? arr.a[1] : val,
        pos != 2 ? arr.a[2] : val,
        pos != 3 ? arr.a[3] : val,
        pos != 4 ? arr.a[4] : val,
        pos != 5 ? arr.a[5] : val,
        pos != 6 ? arr.a[6] : val,
        pos != 7 ? arr.a[7] : val,
        pos != 8 ? arr.a[8] : val,
        pos != 9 ? arr.a[9] : val
      }};
    }
    
    struct array store_two_val(const struct array arr, const struct two_val val, const size_t pos)
    {
      return store_val(store_val(arr,val.a[0],pos),val.a[1],pos+1);
    }
    
    // суперохуительная рекурсивная функция сортировки пузырьком
    struct array_and_status bubble_sort_rec(struct array_and_status state) 
    {
      if (state.pos == 9)
      {
        if (state.is_swap == false) // Ура! Сортировка пузырьком завершена!
        {
          return state;
        }
        else
        { // а иначе нам надо по-новой сортировать!
          return bubble_sort_rec((struct array_and_status){.is_swap = false, .pos=0, .arr = state.arr});
        }
      }
      else
      {
        const struct two_val_and_status tmp = sort2(read_two_val(state.arr, state.pos));
        return bubble_sort_rec(
          (struct array_and_status)
          {
            .is_swap = tmp.is_swap || state.is_swap,
            .pos=state.pos+1,
            .arr = store_two_val(state.arr, tmp.t_v, state.pos)
          }
        );
      }
    }
    
    int main(void)
    {
      const struct array_and_status a = {.is_swap = false, .pos = 0, .arr = {{8,2,4,1,3,5,7,0,6,9}} };
      const struct array_and_status a_sort = bubble_sort_rec(a);
      for(size_t i = 0; i < 10; i++) // ох уж это убогое императивное программирование!!!
      {
        printf("%" PRIu32 ", ", a_sort.arr.a[i]);
      }
      return EXIT_SUCCESS;
    }

    Функциональная сортировка пузырьком
    https://wandbox.org/permlink/dGyvo82lgQGInD0Y

    j123123, 19 Декабря 2021

    Комментарии (107)
  5. Си / Говнокод #27873

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    typedef struct
    {
      int32_t x;
      int32_t y;
    } coord;
    
    coord stack[1000000] = {{0,0}};
    
    size_t stack_end = 1;
    
    int checkstack(coord in)
    {
      for(size_t i = 0; i < stack_end; i++)
      {
        if((stack[i].x == in.x) && (stack[i].y == in.y)) 
        {
          return 0;
        }
      }
      stack[stack_end] = in;
      stack_end += 1;
      return 1;
    }
    
    void consume_char(char ch, coord *c, uint32_t *sum)
    {
      switch( ch )
      {
        case '>':
          c->x += 1;
          break;
        case '<':
          c->x -= 1;
          break;
        case '^':
          c->y += 1;
          break;
        case 'v':
          c->y -= 1;
          break;
        default:
          printf("ERROR!!");
          exit(-1);
      }
      *sum += checkstack(*c);
    }
    
    const char *arr = "^><^>>>^<^v<v^^vv^><<^.....";
    
    
    int main(void)
    {
      const char *arr_ptr = arr;
      coord crd = {0,0};
      uint32_t sum = 1;
      while (*arr_ptr != '\0')
      {
        //printf("test\n");
        consume_char(*arr_ptr, &crd, &sum);
        arr_ptr++;
      }
      printf("%" PRIu32 "\n", sum);
      return EXIT_SUCCESS;
    }

    Решил от нехуй делать попроходить https://adventofcode.com/
    Вот например https://adventofcode.com/2015/day/3

    j123123, 13 Декабря 2021

    Комментарии (34)
  6. Си / Говнокод #27825

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    #include <limits.h>
    typedef unsigned __int128 uint128_t;
    typedef __int128 int128_t;
    
    // в чем тут по-вашему баг ?
    uint64_t add1bit_left_1_bug(const uint64_t a, int shift)
    {
      return ~(~(a << shift) >> shift);
    }
    
    uint64_t add1bit_left_1(const uint64_t a, int shift)
    {
      return ~((uint128_t)~(uint64_t)((uint128_t)a << shift) >> shift);
    }
    
    // или тут ?
    uint64_t add1bit_left_2_bug(const uint64_t a, int shift)
    {
      return a | (uint64_t)(UINT64_MAX << (CHAR_BIT * sizeof(uint64_t) - shift));
    }
    
    uint64_t add1bit_left_2(const uint64_t a, int shift)
    {
      return a | (uint64_t)((uint128_t)-1 << (CHAR_BIT * sizeof(uint64_t) - shift));
    }
    
    uint64_t add1bit_left_3(const uint64_t a, int shift)
    {
      if (shift == 0) return a;
      return (uint64_t)((int64_t)((a << (shift-1)) | ((uint64_t)1 << (CHAR_BIT * sizeof(uint64_t) - 1)) ) >> (shift-1)); // а тут вообще UB
    }
    
    
    int main(void)
    {
      // tests
      for (int i = 0; i <= 64; i++) // пробуем сдвигать от 0 до 64 включительно.
      {
        // for (uint128_t j = 0; j < UINT64_MAX+1; j++) - какая формальная верификация )))
        for (uint64_t j = 0; j < 100; j++)
        {
          if (add1bit_left_1(j,i) != add1bit_left_2(j,i))
          {
            printf("error1\n");
            printf("%" PRIu64 " %d\n", j,i);
            return EXIT_FAILURE;
          }
          if (add1bit_left_1(j,i) != add1bit_left_3(j,i))
            printf("error2\n");
          if (add1bit_left_2(j,i) != add1bit_left_3(j,i))
            printf("error3\n");
        }
      }
      printf("%" PRIX64 "\n", add1bit_left_1(0,0));
      printf("%" PRIX64 "\n", add1bit_left_2(0,0));
      printf("%" PRIX64 "\n", add1bit_left_3(0,0));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,0));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,0));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,1));
      printf("%" PRIX64 "\n", add1bit_left_2(0,1));
      printf("%" PRIX64 "\n", add1bit_left_3(0,1));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,1));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,1));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,2));
      printf("%" PRIX64 "\n", add1bit_left_2(0,2));
      printf("%" PRIX64 "\n", add1bit_left_3(0,2));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,2));
      puts("");
      printf("%" PRIX64 "\n", add1bit_left_1(0,64));
      printf("%" PRIX64 "\n", add1bit_left_2(0,64));
      printf("%" PRIX64 "\n", add1bit_left_3(0,64));
      printf("%" PRIX64 " - bug\n", add1bit_left_1_bug(0,64));
      printf("%" PRIX64 " - bug\n", add1bit_left_2_bug(0,64));
      return EXIT_SUCCESS;
    }

    Вореанты говнофункции, которая сдвигает влево uint64_t но набрасывает единички вместо ноликов.

    j123123, 17 Ноября 2021

    Комментарии (22)
  7. Си / Говнокод #27559

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    #include <stdlib.h>
    #include <stdio.h>
    #include <inttypes.h>
    
    #define STRING 0
    #define INTEGER 1
    
    
    #define CAT(x,y) x ## _ ## y
    #define J(x,y)  CAT(x,y)
    
    
    typedef union
    {
      char *J(v, STRING);
      int J(v,INTEGER);
    } Un;
    
    typedef struct
    {
      uint8_t Obj_t;
      Un u;
    } Object;
    
    #define IF_INSTOF(var, t, newvar) \
    if(var.Obj_t == t) \
    { \
      typeof(var.u.J(v,t)) *newvar = &var.u.J(v,t);
    
    int main(void)
    {
      Object obj1 = {STRING, {.J(v,STRING) = "1"}};
      
      IF_INSTOF(obj1,STRING,str)
        printf("String: %s\n", *str);
      }
      else
      {
        printf("Not a string\n");
      }
    
      Object obj2 = {INTEGER, {.J(v,INTEGER) = 1}};
      IF_INSTOF(obj2,INTEGER,i)
        printf("Integer: %d\n", *i);
      }
      else
      {
        printf("Not an Integer\n");
      }
    
      return EXIT_SUCCESS;
    }

    Вот такие смарткасты через препроцессор.

    https://govnokod.ru/27556#comment655527

    j123123, 13 Августа 2021

    Комментарии (32)
  8. Си / Говнокод #27525

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    typedef struct list list;
    
    struct list
    {
      list* next;
      uint32_t data;
    };
    
    #define ADD_LIST(ptr, val) \
    do { \
      (ptr)->next = (list *)alloca(sizeof(list)); \
      (ptr)->next->data = val; \
      (ptr)->next->next = NULL;\
    } while (0)
    
    // https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
    #define INIT_LIST(val) \
    ({ \
      list *INIT_LIST = (list *)alloca(sizeof(list)); \
      INIT_LIST->data = val; \
      INIT_LIST->next = NULL; \
      INIT_LIST; \
    })
    
    
    int main(void)
    {
      list *a = INIT_LIST(5);
      ADD_LIST(a,10);
      ADD_LIST(a->next,15);
      ADD_LIST(a->next->next,20);
      ADD_LIST(a->next->next->next,25);
      ADD_LIST(a->next->next->next->next,30);
    
      for(list *ptr = a; ptr != NULL; ptr = ptr->next)
      {
        printf("%d ", ptr->data);
      }
    
      return EXIT_SUCCESS;
    }

    А можно ли в крестоговне так сделать без Сишного Препроцессора?

    j123123, 19 Июля 2021

    Комментарии (96)
  9. Си / Говнокод #27477

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    #include <stdio.h>
    #include <stdlib.h>
    
    #define DEREF(x) ({*(x);})
    #define PTR(x) ({&(x);})
    #define PTR_T(x) typeof(typeof(x) *)
    #define DEREF_T(x) typeof( ({typeof(x) DEREF_T; *DEREF_T;}) )
    
    
    void add5(PTR_T(int) a)
    {
      DEREF(a)+= 5;
    }
    
    int main(void)
    {
      int a = 0;
      printf("%d\n", a);
      add5(PTR(a));
      printf("%d\n", a);
      
      int b = 5;
      PTR_T(b) b_p = PTR(b); // int *
      printf("%d\n", DEREF(b_p) );
      
      DEREF_T(b_p) c = 666; // int
      printf("%d", c);
      
      return EXIT_SUCCESS;
    }

    https://govnokod.ru/27476#comment637183

    ASD_77:
    потому что я люблю Си и С++ но ненажижу * и & ... поэтому я решил исправить этот недочет в мире

    Исправил, проверь. Компилится только в GCC, всё-таки Clang не 100% совместим c гнутыми расширениями.

    j123123, 21 Июня 2021

    Комментарии (64)
  10. Си / Говнокод #27345

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    #include <stdio.h>
    #include <stdlib.h>
    
    #define SPLICE(a,b) SPLICE_1(a,b)
    #define SPLICE_1(a,b) SPLICE_2(a,b)
    #define SPLICE_2(a,b) a##b
    
    
    #define PP_ARG_N( \
              _1,  _2,  _3,  _4,  _5,  _6,  _7,  _8,  _9, _10, \
             _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
             _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
             _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
             _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
             _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
             _61, _62, _63, N, ...) N
    
    /* Note 63 is removed */
    #define PP_RSEQ_N()                                        \
             62, 61, 60,                                       \
             59, 58, 57, 56, 55, 54, 53, 52, 51, 50,           \
             49, 48, 47, 46, 45, 44, 43, 42, 41, 40,           \
             39, 38, 37, 36, 35, 34, 33, 32, 31, 30,           \
             29, 28, 27, 26, 25, 24, 23, 22, 21, 20,           \
             19, 18, 17, 16, 15, 14, 13, 12, 11, 10,           \
              9,  8,  7,  6,  5,  4,  3,  2,  1,  0
    
    #define PP_NARG_(...)    PP_ARG_N(__VA_ARGS__)    
    
    /* Note dummy first argument _ and ##__VA_ARGS__ instead of __VA_ARGS__ */
    #define PP_NARG(...)     PP_NARG_(_, ##__VA_ARGS__, PP_RSEQ_N())
    
    #define FIND_NONNULL_1(RES) \
      ((RES = (char *)(NULL)))
    
    #define FIND_NONNULL_2(RES, VAR) \
      ((RES = (char *)(VAR)))
    
    #define FIND_NONNULL_3(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_2(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_4(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_3(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_5(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_4(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_6(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_5(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_7(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_6(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_8(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_7(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_9(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_8(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_10(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_9(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_11(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_10(RES,__VA_ARGS__))
    
    #define FIND_NONNULL_12(RES, VAR, ...) \
      (((RES = (char *)(VAR)) != NULL)?RES:FIND_NONNULL_11(RES,__VA_ARGS__))
    
    // etc ...
    
    #define FIND_NONNULLS_(N, ...) \
      SPLICE(FIND_NONNULL_, N)(__VA_ARGS__)
    
    #define FIND_NONNULLS(...) \
    ({ \
      char *FIND_NONNULLS; \
      FIND_NONNULLS_(PP_NARG(FIND_NONNULLS, __VA_ARGS__), FIND_NONNULLS, __VA_ARGS__); \
      FIND_NONNULLS; \
    })
    
    char *side_effect_null(void)
    {
      printf("!!null!!\n");
      return NULL;
    }
    
    char *side_effect_test(void)
    {
      printf("!!test!!\n");
      return "test";
    }
    
    int main(void)
    {
      printf( "result:%s\n", FIND_NONNULLS(0,side_effect_null(),0,side_effect_test(),0,0,side_effect_test(),"govno", side_effect_test()) );
      return EXIT_SUCCESS;
    }

    Это типа как short-circuit evaluation чтоб по цепочке хрень возвращающую строку вызывать, и там те функции хуйпойми сколько аргументов могут принимать (но там может быть константа, тогда естественно нихрена не надо вызывать) пока оно не вернет не-NULL. Как только вернуло не-NULL то вернуть это и дальше ничего не вызывать, а то там сайд эффекты всякие ненужные будут. А если не-NULL так и не нашло, вернуть NULL

    j123123, 09 Апреля 2021

    Комментарии (24)
  11. Си / Говнокод #27344

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    // https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    
    
    
    int main(void)
    {
      char *a = "petuh";
      if(({bool ret = 0;if(a[0]=='p')if(a[1]=='e')if(a[2]=='t')if(a[3]=='u')if(a[4]=='h')ret=1;ret;}))
      {
        puts(a);
      }
      return EXIT_SUCCESS;
    }

    Интересное расширение.

    j123123, 09 Апреля 2021

    Комментарии (33)