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

    +10

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public ref class Form1 : public System::Windows::Forms::Form
    {
    private: char * StrToCharArray ( System::String ^ inStr )
    {
        pin_ptr<const wchar_t> wch_basename = PtrToStringChars( inStr );
        size_t convertedChars = 0; size_t  sizeInBytes = ((inStr->Length + 1) * 2);
        char * ch_basename = (char *)malloc(sizeInBytes);
        wcstombs_s(&convertedChars, ch_basename, sizeInBytes, wch_basename, sizeInBytes);
     return ch_basename;
    }
    }

    C++/CLI

    sokol, 11 Июня 2013

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

    +16

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #define Throw(exc, msg) do {  \
       std::stringstream exc_str; \
       exc_str << __FILE__ << ":" << __LINE__ \
       << ": " << __func__ << "(): " << msg;  \
       throw exc(exc_str.str()); \
       } while(0)
    
    Throw(std::runtime_error, "test");

    terminate called after throwing an instance of 'std::runtime_error'
    what(): main.cpp:22: main(): Error

    Как вам?

    an0nym, 10 Июня 2013

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

    +14

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    template<typename U>
    shared_ptr(const shared_ptr<U> & ptr) throw()
    	: m_value(0)
    	, m_ref_count(0)
    {
    	m_value = static_cast<T *>(ptr.get());
    	if(m_value)
    	{
    		m_ref_count = reinterpret_cast<const shared_ptr &>(ptr).m_ref_count;
    		++*m_ref_count;
    	}
    }

    Выражаясь метафорично, я работаю на велосипедном заводе.

    Xom94ok, 09 Июня 2013

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

    +18

    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
    word mofs[]={0,
                 31,
                 31+28,
                 31+28+31,
                 31+28+31+30,
                 31+28+31+30+31,
                 31+28+31+30+31+30,
                 31+28+31+30+31+30+31,
                 31+28+31+30+31+30+31+31,
                 31+28+31+30+31+30+31+31+30,
                 31+28+31+30+31+30+31+31+30+31,
                 31+28+31+30+31+30+31+31+30+31+30
    //          ,31+28+31+30+31+30+31+31+30+31+30+31
                };

    "Класс для работы с датами" взятый отсюда: http://yun.complife.ru/soft.htm

    bormand, 07 Июня 2013

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

    +8

    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
    void Cluster::CloseConnection()
    {
        m_Connection->close();
        if (!m_Connection->IsOK())
            throw ConnectionError(m_Connection->LastError());
    }
    
    void ClusterGroup::RemoveCluster(int iIndex)
    {
        Cluster *pSubCluster = m_SubClusters->At[i];
        pSubCluster->CloseConnection();
        delete pSubCluster;
        m_SubClusters->SetAt(i, NULL);
    }

    И потекло...

    Lavir_the_Whiolet, 06 Июня 2013

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

    +35

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    #if defined(_WIN32) || defined(_WIN64)
        ofstream outfile("help.txt");
        outfile << message << endl;
        system("notepad.exe help.txt");
     #else
        cout << message ;
    #endif

    Зачем бороться с юникодом в консоли, когда есть блокнот?

    crastinus, 03 Июня 2013

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

    +23

    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
    #ifndef SAFE_RELEASE
    #define SAFE_RELEASE(x) \
       if(x != NULL)        \
       {                    \
          x->Release();     \
          x = NULL;         \
       }
    #endif
    
    #define SAFE_DELETE(a) if( (a) != NULL ) delete (a); (a) = NULL;
    
    #ifndef SAFE_ARRAY_DELETE
    #define SAFE_ARRAY_DELETE(x) \
       if(x != NULL)             \
       {                         \
          delete[] x;            \
          x = NULL;              \
       }
    #endif
    
    #define SAFE_FREE( p )      if( p ) { free( p ) ; p=NULL ; }

    Я вот все никак не могу забыть старый код из доков макрософт по COM, а также из книги Андре Ла Мота.

    Два макроса до сих пор висят среди доков на сайте мс (по коду догадаетесь какие):

    http://msdn.microsoft.com/ru-RU/library/windows/desktop/dd743946(v=vs.85).aspx

    LispGovno, 01 Июня 2013

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

    +14

    1. 1
    std::set_unexpected( [] () {} );

    Студия достала и не позволяла обрабатывать исключения, а они нужны были для демонстрации работы, в итоге навесил такой костыль и включил SEH исключения в параметрах компиляции.

    maksim_ovcharik, 29 Мая 2013

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

    +24

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    int randomize(int Min, int Max)
    {
    qsrand(QTime::currentTime().msec());
    if (Min > Max)
    {
    int Temp = Min;
    Min = Max;
    Max = Temp;
    }
    return ((qrand()%(Max-Min+1))+Min);
    }

    Всё хорошо?

    Hackeridze, 29 Мая 2013

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

    +26

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (Keys == 0 && Shift.Contains(ssShift) == false && Shift.Contains(ssCtrl) == false && Shift.Contains(ssAlt) == false) { ... }
    if (Keys == 1 && Shift.Contains(ssShift) == true && Shift.Contains(ssCtrl) == false && Shift.Contains(ssAlt) == false) { ... }
    if (Keys == 2 && Shift.Contains(ssShift) == false && Shift.Contains(ssCtrl) == true && Shift.Contains(ssAlt) == false) { ... }
    if (Keys == 3 && Shift.Contains(ssShift) == false && Shift.Contains(ssCtrl) == false && Shift.Contains(ssAlt) == true) { ... }
    if (Keys == 4 && Shift.Contains(ssShift) == true && Shift.Contains(ssCtrl) == true && Shift.Contains(ssAlt) == false) { ... }
    if (Keys == 5 && Shift.Contains(ssShift) == true && Shift.Contains(ssCtrl) == false && Shift.Contains(ssAlt) == true) { ... }
    if (Keys == 6 && Shift.Contains(ssShift) == false && Shift.Contains(ssCtrl) == true && Shift.Contains(ssAlt) == true) { ... }
    if (Keys == 7 && Shift.Contains(ssShift) == true && Shift.Contains(ssCtrl) == true && Shift.Contains(ssAlt) == true) { ... }

    Без комментариев. Думаю, тут и так все понятно ;)

    bormand, 23 Мая 2013

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