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

    +10

    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
    #define class KOKOKO
    #include <sys/shutdown.h>
    #undef class
    
    /* внутри sys/shutdown.h:
    
    typedef struct
    {
        uint64_t start_time;
        pid_t pid;
        int8_t class;
        uint8_t padding[3];
        char *name;
    } ProcessInfo_t;
    */

    перезагружаем qnx neutrino из крестового кода

    Xom94ok, 22 Марта 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    #include <vector>
    
    template <typename T>
    void FreeAll( T & t ) {
        T tmp;
        t.swap( tmp );
    }

    3_dar, 20 Марта 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
      * @brief Макрос вызова функции изменения имени файла лога ПИМ
      *
      * @param FILE_NAME  Имя файла лога
      *
      * @return Ничего
      */
    #define LOG_PIM_SET_FILE_NAME(FILE_NAME)  Soc::setLogFileName(FILE_NAME)

    Самый нужный макрос в мире

    cpp_best_practo, 17 Марта 2016

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

    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
    #include <iostream>
    
    using namespace std;
    
    int main(){
        int n = 60;
        int a = 1 << n;
        cout << a << endl;
        n = 33;
        a = 1 << n;
        cout << a << endl;
        unsigned m = 33;
        unsigned b = 1u << m;
        cout << b << endl;
        // a = 1 << 32;
        // cout << a << endl;
        return 0;
    }

    Моар:
    http://acm.math.spbu.ru/~kunyavskiy/cpp/sol02.cpp

    UltimateDelighter, 16 Марта 2016

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

    +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
    void g()
    {
        int sum;
        auto rec = [&sum](int i) -> int
        {
            static int (*inner)(int&, int) = [](int& _sum, int i)->int 
            {
                _sum += i;
                return i>0 ? inner(_sum, i-1)*i : 1; 
            };
            return inner(sum, i);
        };
    }

    LispGovno, 15 Марта 2016

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    QMutableListIterator<AISObjectQML *> it(m_visibleList);
    if (it.hasNext()) {
        AISObjectQML *v = it.next();
        if (v) { // здесь должен быть while, но, признаться, на это уже посрать
            delete v;
        }
    }
    m_visibleList.clear();

    Есть люди, которые придумали концепцию итераторов для реализации generic алгоритмов. А есть люди, которые любят итераторы, но не любят generic алгоритмы. Ведь с ними код не внушает ужаса и рвотных позывов

    Antervis, 15 Марта 2016

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

    +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
    FOREACHINLIST(CBrushMip, bm_lnInBrush, penbr->GetBrush()->br_lhBrushMips, itbm)
      {
        CBrushMip &brmip=*itbm;
        FOREACHINDYNAMICARRAY(itbm->bm_abscSectors, CBrushSector, itbsc)
        {
          CBrushSector &bsc=*itbsc;
          FOREACHINSTATICARRAY(itbsc->bsc_abpoPolygons, CBrushPolygon, itbpo)
          {
            CBrushPolygon &bpo=*itbpo;
            CheckOnePolygon(bsc, bpo);
          }
        }
      }

    И такое используется во всём SeriousEngine

    mittorn, 13 Марта 2016

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    void MultMatrix(const GLfloat m1[16], const GLfloat m2[16], GLfloat result[16])
    {
      glLoadMatrixf(m1);
      glMultMatrixf(m2);
      glGetFloatv(GL_MODELVIEW_MATRIX, result);
    }

    LispGovno, 12 Марта 2016

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

    +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
    13. 13
    catch(...)
    {
    	static int i = 0;                     
    	//if we enter this catch clause more than 1 time
    	//it is very likely that the RestartSystem() command
    	//did not succeed. If this is the case we just exit.
    	if(i>0)
    		exit(0);
    	else
    		MonitorT::GetInstance()->RestartSystem();
    	i++;
    	throw;
    }

    Навеяло...

    blackhearted, 11 Марта 2016

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

    +6

    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
    //		implicit_cast< >
    // I believe this was originally going to be in the C++ standard but 
    // was left out by accident. It's even milder than static_cast.
    // I use it instead of static_cast<> to emphasize that I'm not doing
    // anything nasty. 
    // Usage is identical to static_cast<>
    template <class OutputClass, class InputClass>
    inline OutputClass implicit_cast(InputClass input){
    	return input;
    }
    
    //		horrible_cast< >
    // This is truly evil. It completely subverts C++'s type system, allowing you 
    // to cast from any class to any other class. Technically, using a union 
    // to perform the cast is undefined behaviour (even in C). But we can see if
    // it is OK by checking that the union is the same size as each of its members.
    // horrible_cast<> should only be used for compiler-specific workarounds. 
    // Usage is identical to reinterpret_cast<>.
    
    // This union is declared outside the horrible_cast because BCC 5.5.1
    // can't inline a function with a nested class, and gives a warning.
    template <class OutputClass, class InputClass>
    union horrible_union{
    	OutputClass out;
    	InputClass in;
    };
    
    template <class OutputClass, class InputClass>
    inline OutputClass horrible_cast(const InputClass input){
    	horrible_union<OutputClass, InputClass> u;
    	// Cause a compile-time error if in, out and u are not the same size.
    	// If the compile fails here, it means the compiler has peculiar
    	// unions which would prevent the cast from working.
    	typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) 
    		&& sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1];
    	u.in = input;
    	return u.out;
    }

    Боль и страдание шаблонного программирования на С++98. Комменты и названия доставляют.

    gorthauer87, 11 Марта 2016

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