1. C++ / Говнокод #17616

    +55

    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
    uint8_t const Q_ROM QF_div8Lkup[65] = {
        static_cast<uint8_t>(0), // unused location
        static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7), static_cast<uint8_t>(7),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7), static_cast<uint8_t>(7),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7)
    };
    
    // ....
    
        //! the function evaluates to TRUE if the priority set has the element n.
        bool hasElement(uint_fast8_t const n) const {
            uint_fast8_t const m =
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_div8Lkup[n]));
            return ((m_bits[m]
                      & static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[n])))
                   != static_cast<uint_fast8_t>(0));
        }
    
        //! insert element \a n into the set, n = 1..64
        void insert(uint_fast8_t const n) {
            uint_fast8_t m =
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_div8Lkup[n]));
            m_bits[m] |= static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[n]));
            m_bytes   |=
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[m
                                              + static_cast<uint_fast8_t>(1)]));
        }

    делим на 8 в индустриальном С++. это такой специальный вариант крестов где пользователям сначала лоботомию делают.

    из реализации bitset'а. insert() приведен в качестве примера.

    Dummy00001, 11 Февраля 2015

    Комментарии (16)
  2. C++ / Говнокод #17612

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    static uint8_t const FREE = static_cast<uint8_t>(0);
    static uint8_t const USED = static_cast<uint8_t>(1);
    
    static char_t const * const THINKING = &"thinking"[0];
    static char_t const * const HUNGRY   = &"hungry  "[0];
    static char_t const * const EATING   = &"eating  "[0];

    Из демы QP/C++ библиотеки. Вот в таком духе очень много кода.

    Индустриальщики, после перехода на С++, похоже очень сильно страдают по отсутствию pre-ANSI C какашек, и изобретают новые.

    Dummy00001, 10 Февраля 2015

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

    +66

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Компиляторами являются:
    1. С++
    2. Паскаль
    3. Ассемблер
    4. Unix

    Какой-то жопоразрывающий тест по с++ из ивановской области
    http://hashcode.ru/questions/398214/

    Fike, 10 Февраля 2015

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

    +57

    1. 1
    curBlock = &(game->codeblocks[getCurBlockId((*(JumpLine *)(curBlock->getLine())).getJumpName())]);

    ximximik, 09 Февраля 2015

    Комментарии (0)
  5. C++ / Говнокод #17600

    +60

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    const QStringList numbers = QString::fromUtf8("Ноль|" \
                                                                                         "Один|" \
                                                                                         "Два|" \
                                                                                         "Три|" \
                                                                                         "Четыре|" \
                                                                                         "Пять|" \
                                                                                         "Шесть|" \
                                                                                         "Семь|" \
                                                                                         "Восемь|" \
                                                                                         "Девять" \
                                                                                        ).split('|');

    absolut, 08 Февраля 2015

    Комментарии (24)
  6. C++ / Говнокод #17592

    +57

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    template <class T>
    T checked_signed_add(T a, T b) {
        if (a >= 0) {
            if (b >= 0 && std::numeric_limits<T>::max() - a < b)
                throw std::runtime_error("Integer overflow");
        } else {
            if (b < 0 && std::numeric_limits<T>::min() - a > b)
                throw std::runtime_error("Integer overflow");
        }
        return a + b;
    }

    Кресты. Знаковые числа. Сложение.

    http://ideone.com/qxyAoG

    bormand, 06 Февраля 2015

    Комментарии (33)
  7. C++ / Говнокод #17591

    +57

    1. 1
    2. 2
    3. 3
    static int lowercase(const char *s) {
      return tolower(* (const unsigned char *) s);
    }

    Byte-fuck

    blackhearted, 06 Февраля 2015

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

    +57

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    char val;
    //...
    switch(val)
    {
       case '0': mOn = true; break;
       default: mOn = false; break;
    }

    absolut, 05 Февраля 2015

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

    +56

    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
    void split_int(int num)
    {
        int i1,i2,i3,i4,i5,i6,i7,i8,i9,MAX = 10;
        for(i1 = 1; i1 < MAX; i1++)
        {
            if(i1 == num)
                    printf("%d = %d\r\n",i1,num);
            for(i2 = 1; i2 < MAX; i2++)
            {
                if(i1 + i2 == num)
                    printf
                    (
                        "%d + %d = %d\r\n",
                        i1,i2,num
                    );
                for(i3 = 1; i3 < MAX; i3++)
                {
                    if(i1 + i2 + i3 == num)
                        printf
                        (
                            "%d + %d + %d = %d\r\n",
                            i1,i2,i3,num
                        );
                    for(i4 = 1; i4 < MAX; i4++)
                    {
                        if(i1 + i2 + i3 + i4 == num)
                            printf
                            (
                                "%d + %d + %d + %d = %d\r\n",
                                i1,i2,i3,i4,num
                            );
                        for(i5 = 1; i5 < MAX; i5++)
                        {
                            if(i1 + i2 + i3 + i4 + i5 == num)
                                printf
                                (
                                    "%d + %d + %d + %d + %d= %d\r\n",
                                    i1,i2,i3,i4,i5,num
                                );
                            for(i6 = 1; i6 < MAX; i6++)
                            {
                                if(i1 + i2 + i3 + i4 + i5 + i6 == num)
                                    printf
                                    (
                                        "%d + %d + %d + %d + %d + %d = %d\r\n",
                                        i1,i2,i3,i4,i5,i6,num
                                    );
                                for(i7 = 1; i7 < MAX; i7++)
                                {
                                    if(i1 + i2 + i3 + i4 + i5 + i6 + i7 == num)
                                        printf
                                        (
                                            "%d + %d + %d +%d + %d + %d + %d = %d\r\n",
                                            i1,i2,i3,i4,i5,i6,i7,num
                                        );
                                    for(i8 = 1; i8 < MAX; i8++)
                                    {
                                        if(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 == num)
                                            printf
                                            (
                                                "%d + %d + %d + %d + %d + %d + %d + %d = %d\r\n",
                                                i1,i2,i3,i4,i5,i6,i7,i8,num
                                            );
                                        for(i9 = 1; i9 < MAX; i9++)
                                            if(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 == num)
                                                printf
                                                (
                                                    "%d + %d + %d + %d + %d + %d + %d + %d + %d = %d\r\n",
                                                    i1,i2,i3,i4,i5,i6,i7,i8,i9,num
                                                );
                                    }
     
                                }
                            }
                        }
                    }
                }
            }
        }
        printf("\r\n");
    }

    С одного известного форума.

    DesmondHume, 04 Февраля 2015

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

    +136

    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
    #include <stdint.h>
    #include <Windows.h>
    #include <intrin.h>
    
    typedef long dt;
    
    namespace {
    	dt InitializationIsInProgress = 0;
    	dt InitializationIsFinished = 0;
    }
    
    dt InterlockedLoad(dt volatile * t){
    	return InterlockedCompareExchange(t, 0, 0);
    }
    
    dt InterlockedAssign(dt volatile * t, dt v){
    	dt c = 0;
    	while (c = InterlockedCompareExchange(t, v, c));
    }
    
    void InitializeSystem(){
    	if (InterlockedLoad(&InitializationIsFinished) == 1)
    		return;
    	while (InterlockedCompareExchange(&InitializationIsInProgress, 1, 0) == 1) Sleep(0);
    	//__ReadWriteBarrier();
    	if (InterlockedLoad(&InitializationIsFinished) == 1)
    		return;
    	Work();
    	InterlockedAssign(&InitializationIsFinished, 1);
    	InterlockedAssign(&InitializationIsInProgress, 0);
    }

    Не судите строга. Воспользуюсь как пастебином. Если найдете ошибки - пришлю пирожок.

    LispGovno, 04 Февраля 2015

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