1. Список говнокодов пользователя j123123

    Всего: 338

  2. C++ / Говнокод #25359

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    // https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
    
    // The Curiously Recurring Template Pattern (CRTP)
    template<class T>
    class Base
    {
        // methods within Base can use template to access members of Derived
    };
    class Derived : public Base<Derived>
    {
        // ...
    };

    > The Microsoft Implementation of CRTP in Active Template Library (ATL) was independently discovered, also in 1995 by Jan Falkin who accidentally derived a base class from a derived class. Christian Beaumont, first saw Jan's code and initially thought it couldn't possibly compile in the Microsoft compiler available at the time. Following this revelation that it did indeed work, Christian based the entire ATL and Windows Template Library (WTL) design on this mistake.

    А какая ошибка по-вашему положена в основу всего дизайна языка C++?

    j123123, 06 Февраля 2019

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

    −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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    int main(void)
    {
      char a[8], b[8];
      char *a_ptr = a+8;
      char *b_ptr = b;
      printf("a_ptr = %p, b_ptr = %p\n", a_ptr, b_ptr);
      if (a_ptr != b_ptr)
      {
        printf("a_ptr != b_ptr\n");
      }
      else
      {
        printf("a_ptr == b_ptr\n");
      }
      
      
      if ((uintptr_t)a_ptr != (uintptr_t)b_ptr)
      {
        printf("(uintptr_t)a_ptr != (uintptr_t)b_ptr\n");
      }
      else
      {
        printf("(uintptr_t)a_ptr == (uintptr_t)b_ptr\n");
      }
      return EXIT_SUCCESS;
    }

    Что по-вашему тут происходит?

    j123123, 02 Февраля 2019

    Комментарии (39)
  4. C++ / Говнокод #25343

    −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
    // https://habr.com/ru/company/jugru/blog/438260/
    
    template<Semiregular T>
    struct maybe_view : view_interface<maybe_view<T>> {
      maybe_view() = default;
      maybe_view(T t) : data_(std::move(t)) {
      }
      T const *begin() const noexcept {
        return data_ ? &*data_ : nullptr;
      }
      T const *end() const noexcept {
        return data_ ? &*data_ + 1 : nullptr;
      }
    private:
      optional<T> data_{};
    };
    inline constexpr auto for_each =
      []<Range R,
         Iterator I = iterator_t<R>,
         IndirectUnaryInvocable<I> Fun>(R&& r, Fun fun)
            requires Range<indirect_result_t<Fun, I>> {
          return std::forward<R>(r)
            | view::transform(std::move(fun))
            | view::join;
      };
    inline constexpr auto yield_if =
      []<Semiregular T>(bool b, T x) {
        return b ? maybe_view{std::move(x)}
                 : maybe_view<T>{};
      };
    
    /*
    > Быть может, что для кого-то это язык родной, но для меня всё
    это ощущается как если бы кто-то решил, что Perl излишне читабельный,
    а Brainfuck — излишне нечитабельный, поэтому давайте целиться между
    ними. Я программировал в основном на C++ все последние 20 лет. Может
    быть, я слишком тупой, чтобы во всём этом разобраться, отлично.
    */

    Какой багор)))

    j123123, 31 Января 2019

    Комментарии (11)
  5. Куча / Говнокод #25340

    +1

    1. 1
    https://i.imgur.com/7uRLULs.mp4

    Аппаратная нейросеть в мозгах петуха совершила ошибку классификации.

    j123123, 30 Января 2019

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

    +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
    void add_SSE(uint8_t a[static 7], uint8_t b[static 7], uint8_t out[static 7])
    {
      uint64_t a_64 = 0;
      uint64_t b_64 = 0;
      for (size_t i = 0; i < 7; i++) // можно наанроллить
      {
        a_64 |= (uint64_t)a[i] << (i*9);
        b_64 |= (uint64_t)b[i] << (i*9);
      }
      
      uint64_t c_64 = a_64 + b_64;
      
      for (size_t i = 0; i < 7; i++) // можно наанроллить
      {
        out[i] = (uint64_t)c_64 >> (i*9);
      }
    }

    SSE

    j123123, 28 Января 2019

    Комментарии (32)
  7. Java / Говнокод #25332

    +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
    // https://github.com/TigerVNC/tigervnc/blob/8c6c584377feba0e3b99eecb3ef33b28cee318cb/java/com/jcraft/jsch/Buffer.java#L65-L85
    
      public void putInt(int val) {
        tmp[0]=(byte)(val >>> 24);
        tmp[1]=(byte)(val >>> 16);
        tmp[2]=(byte)(val >>> 8);
        tmp[3]=(byte)(val);
        System.arraycopy(tmp, 0, buffer, index, 4);
        index+=4;
      }
      public void putLong(long val) {
        tmp[0]=(byte)(val >>> 56);
        tmp[1]=(byte)(val >>> 48);
        tmp[2]=(byte)(val >>> 40);
        tmp[3]=(byte)(val >>> 32);
        System.arraycopy(tmp, 0, buffer, index, 4);
        tmp[0]=(byte)(val >>> 24);
        tmp[1]=(byte)(val >>> 16);
        tmp[2]=(byte)(val >>> 8);
        tmp[3]=(byte)(val);
        System.arraycopy(tmp, 0, buffer, index+4, 4);
        index+=8;
      }

    Жабовское байтоебство (судя по всему это такой ntohl) из реализации VNC.
    Вот интересно, в жабке-то unsigned типов нет нихера, но почему-то сделали unsigned двоичный сдвиг (>>>), который работает для этих встроенных signed типов как если б это были unsigned. А как насчет unsigned умножения и деления (сложение и вычитание - то один хер, без разницы, если у нас two's complement)?

    j123123, 28 Января 2019

    Комментарии (58)
  8. C++ / Говнокод #25327

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    https://www.opennet.ru/opennews/art.shtml?num=50026
    
    После двух лет разработки компания The Qt Company представила
    компактный встроенный http-сервер для Qt, доступный для
    разработчиков приложений в виде класса QHttpServer. Сервер
    пока развивается как экспериментальный проект Qt Labs, но
    запланирован для включения в основной состав Qt 6.

    Вот жеж этим [censored] делать нехер. Вы уже в Qt встроили жабаскрипт ( https://doc.qt.io/qt-5/topics-scripting.html ), и даже встроили браузер, но вам этого мало, вы еще и вебсервер встроили. Встройте еще туда и PHP, чтоб вообще всё возможное говно в себя вобрать

    j123123, 26 Января 2019

    Комментарии (34)
  9. C# / Говнокод #25320

    +4

    1. 1
    2. 2
    Yandere Simulator
    https://f0ck.me/b/09d3f680.mp4

    j123123, 22 Января 2019

    Комментарии (14)
  10. C++ / Говнокод #25319

    +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
    // https://www.tutorialspoint.com/Read-a-character-from-standard-input-without-waiting-for-a-newline-in-Cplusplus
    
    
    
    // A portable solution doesn't exist for doing this. On windows, you can use the getch() function from the conio(Console I/O) library to get characters pressed. For example,
    
    #include<iostream>
    #include<conio.h>
    using namespace std;
    int main() {
        char c;
        while(1){ // infinite loop
            c = getch();
            cout << c;
        }
    }
    
    // This will output whatever character you input to the terminal. Note that this will only work on windows as the conio library exists only on windows. On UNIX, you can achieve this by entering in system raw mode. For example,
    
    #include<iostream>
    #include<stdio.h>
    int main() {
        char c;
       // Set the terminal to raw mode
        system("stty raw");
        while(1) {
            c = getchar(); 
            // terminate when "." is pressed
            if(c == '.') {
                system("stty cooked");
                exit(0);
            }  
            std::cout << c << " was pressed."<< std::endl;
        }
    }

    Вариант под UNIX еще и очень секурный, ЕВПОЧЯ

    j123123, 22 Января 2019

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

    −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
    void sort8(uint64_t a[8])
    {
      uint64_t a0;
      uint64_t a1;
      uint64_t a2;
      uint64_t a3;
      uint64_t a4;
      uint64_t a5;
      uint64_t a6;
      uint64_t a7;
     
      SORT2(a[0], a[1], a0, a1);
      SORT2(a[2], a[3], a2, a3);
      SORT2(a[4], a[5], a4, a5);
      SORT2(a[6], a[7], a6, a7);
    
      uint64_t a_tmp[8];
    
      MERGE_2_4(a0, a1, a2, a3, a_tmp[0], a_tmp[1], a_tmp[2], a_tmp[3]);
      MERGE_2_4(a4, a5, a6, a7, a_tmp[4], a_tmp[5], a_tmp[6], a_tmp[7]);
    
      uint64_t *ptra1 = &a_tmp[0];
      uint64_t *ptra2 = &a_tmp[4];
      
      for (size_t i = 0; i < 4; i++)
      {
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
      }
    
      for (size_t i = 4; i < 8; i++)
      {
        if (ptra1 == &a_tmp[4])
        {
          while (ptra2 != &a_tmp[8])
          {
            a[i++] = *ptra2;
            ptra2++;
          }
          break;
        }
        
        if (ptra2 == &a_tmp[8])
        {
          while (ptra1 != &a_tmp[4])
          {
            a[i++] = *ptra1;
            ptra1++;
          }
          break;
        }
    
    
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
    
      }
    }

    Мерж сорт, специализированный на 8 элементов. Вот доказательство корректности https://paste.debian.net/hidden/cce6d31a/

    j123123, 13 Января 2019

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