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

    −42

    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
    #include <iostream>
    
    using namespace std;
    int main()
     {
    for(int i = 0x1; 0x1 <= i; i++)
     {
    int a = 0x5;
    int b = 0xa;
     cin >> i;
    if(b || a)
     {
     a += 0x5;
     cout << "\n ";
     cout << "первое условие: ";
     cout << "\n ";
     cout << "переменная a = " << a;
     cout << "\n ";
     cout << "переменная b = " << --b + 0x5 - 0x9;
     cout << "\n";
    goto var;
     }
    else
     {
     var:
     cout << "\n ";
    cout << "второе условие: ";
     a = (0xa - 0x5);
     cout << "\n ";
     cout << "переменная a = " << a;
     cout << "\n ";
     cout << "переменная b = " << ++b;
     cout << "\n";
     }
    break;
     }
    
     system("pause");
    return 0;
     }

    Попросил чела решить классическую задачку - обменять значениями две переменные, не используя третьей

    telhar, 08 Июня 2012

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

    −33

    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
    CArray <CStyle *, CStyle *> m_aStyles;
    
    ...
    
    #define RETURN_TRUE  return *bOk = TRUE, S_OK
    #define RETURN_FALSE return *bOk = FALSE, S_FALSE
    #define RETURN_ERROR(E) \
    	return LastErrorCode = (ERROR_##E), *bOk = FALSE, S_FALSE
    
    ...
    
    // Создание нового стиля (пустого)
    STDMETHODIMP CEffector::AddStyle(VARIANT_BOOL *bOk)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState())
    	
    	CStyle *pNew = new CStyle;
    	if (pNew)
    	{
    		INT n = m_aStyles.GetSize();
    		m_aStyles.Add(pNew);
    		if (m_aStyles.GetSize() <= n)
    			RETURN_ERROR(MEMORY);
    	}
    	else
    		RETURN_ERROR(MEMORY);
    	RETURN_TRUE;
    }
    
    ...
    
    // Получение кода ошибки
    STDMETHODIMP CEffector::GetErrorCode(long *p)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState())
    
    	*p = LastErrorCode;
    	LastErrorCode = ERROR_NONE;
    	return S_OK;
    }

    Мой первый COM-объект.
    1) Если при успешном возвращении метод должен возвращать S_OK, то при ошибке... S_FALSE, наверное.
    2) Только в Дельфи почему-то возвращается не HRESULT, а параметр, помеченный [out]. Поэтому пришлось добавить аргумент *bOk.
    3) Интересно, что делает CArray, когда кончается память.

    Steve_Brown, 08 Июня 2012

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

    −34

    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
    //cgi_http.cpp
    
    #include "http.h"
    #include <cstring>
    #include <cstdlib>
    
    //decodes uri-encorded string
    char* uri_decode(char* source, char* dest)
    {
    //save pointer address for dest
    char* p = dest;
    char* src = source;
    
    while(*src)
    {
    if(src == strstr(src,"%B8"))
    {
    *p = 'ё';
    src = src + 3;
    p++;
    }
    else if(src == strstr(src,"%E9"))
    {
    *p = 'й';
    src = src + 3;
    p++;
    }
    else if(src == strstr(src,"%F6"))
    {
    *p = 'ц';
    src = src + 3;
    p++;
    }
    else if(src == strstr(src,"%F3"))
    {
    *p = 'у';
    src = src + 3;
    p++;
    }
    else if(src == strstr(src,"%EA"))
    {
    *p = 'к';
    src = src + 3;
    p++;
    }
    else if(src == strstr(src,"%E5"))
    {
    *p = 'е';
    src = src + 3;
    p++;
    }
    .......

    Выкладываю свой чатик на С++. PHP не нужен.

    kukuk, 07 Июня 2012

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

    −35

    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
    #ifndef _PERSISTENT_COLLECTION_CPP
    #define _PERSISTENT_COLLECTION_CPP
    
    ////// BASE_CLASS
    #include "Persistent/ObjectP.cpp"
    
    ////// Support
    #include "Persistent/UInt.cpp"
    
    ////// Persistent Level 1
    #include "Persistent/StringP.cpp"
    #include "Persistent/UIntP.cpp"
    #include "Persistent/TimeP.cpp"
    #include "Persistent/StringArrayP.cpp"
    #include "Persistent/BoolP.cpp"
    #include "Persistent/Int64P.cpp"
    #include "Persistent/BinaryP.cpp"
    
    ////// Persistent Level 2
    #include "Persistent/MapStringToObjectPPtr.cpp"
    #include "Persistent/ObjectPArrayPtr.cpp"
    #include "Persistent/ObjectPListPtr.cpp"
    
    ////// Persistent Level 3
    #include "Persistent/PropertySet.cpp"
    
    
    #endif

    Лолшто? Include cpp? 0_o

    kovyl2404, 06 Июня 2012

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

    −30

    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
    BOOL CIniFile::LoadIniFile()
    {
      CString csBuff;
      CFile oIniFile;
      if (oIniFile.Open(csIniFileName, CFile::modeRead))
      {
        ULONGLONG lenReal = oIniFile.GetLength();
        DWORD dwLen = (DWORD) lenReal;
        if (lenReal > UINT_MAX)
        {
          dwLen = UINT_MAX;
          TRACE("ERROR: CIniFile::LoadIniFile();  CFIle::GetLength() > UINT_MAX\n;");
          ASSERT(0);
        }
        if (!dwLen)
          return FALSE;
        boost::scoped_array <char> cBuffer(new char[dwLen]);
        oIniFile.Read(cBuffer.get(), dwLen);
        LoadIniFromBuffer(cBuffer.get(), dwLen);
        oIniFile.Close();
        if (GetCountRecords())
          return TRUE;
      }
      return FALSE;
    }

    boost::scoped_array... nuff said =(

    kovyl2404, 05 Июня 2012

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

    −43

    1. 1
    bool ok = (state == 0) ? false : true;

    И это пишет человек, пишущий на плюсах уже много лет...

    glook, 05 Июня 2012

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

    −34

    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
    int ConditionsTuple(const bool Condition1, const bool Condition2)
    {
    	return (Condition1<<1) + Condition2;
    }
    
    template <bool Condition1, bool Condition2>
    struct TConditionsTuple
    {
    	enum {Result = (Condition1<<1) + Condition2};
    };
    
    float SignedIf(const bool Condition)
    {
    	return Condition ? -1 : 1;
    }
    
    switch (ConditionsTuple(
    					bExpr1,
    					bExpr2
    					))
    	{
    		case TConditionsTuple<1, 1>::Result:
    			return PArc(new TArc(
    							CouplePointAtPrimitive1,
    							CouplePointAtPrimitive2,
    							ArcCoupleCenter,
    							Abs(arcCoupleRadius)
    							));
    		case TConditionsTuple<0, 1>::Result:
    			throw TPrimitive1HalfLengthExpiredException();
    		case TConditionsTuple<1, 0>::Result:
    			throw TPrimitive2HalfLengthExpiredException();
    		case TConditionsTuple<0, 0>::Result:
    			throw TAllPrimitivesHalfLengthExpiredException();			
    	}

    Говногость, 04 Июня 2012

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

    −35

    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
    bool EvtDecay::isCharm(EvtId xid){
    EvtId d0    = EvtPDL::getId(std::string("D0"));
    EvtId d0bar = EvtPDL::getId(std::string("anti-D0"));
    EvtId dp    = EvtPDL::getId(std::string("D+"));
    EvtId dm    = EvtPDL::getId(std::string("D-"));
    EvtId d0h   = EvtPDL::getId(std::string("D0H"));
    EvtId d0l    = EvtPDL::getId(std::string("D0L"));
    EvtId dstp   = EvtPDL::getId(std::string("D*+"));
    EvtId dstm   = EvtPDL::getId(std::string("D*-"));
    EvtId ds0    = EvtPDL::getId(std::string("D*0"));
    EvtId ds0bar = EvtPDL::getId(std::string("anti-D*0"));
    EvtId dsp    = EvtPDL::getId(std::string("D_s+"));
    EvtId dsm    = EvtPDL::getId(std::string("D_s-"));
    EvtId dsstp  = EvtPDL::getId(std::string("D_s*+"));
    EvtId dsstm  = EvtPDL::getId(std::string("D_s*-"));
    EvtId ds0stp = EvtPDL::getId(std::string("D_s0*+"));
    EvtId ds0stm = EvtPDL::getId(std::string("D_s0*-"));
    
     std::vector<EvtId> Vid; Vid.clear();
     Vid.push_back(d0);
     Vid.push_back(d0bar);
     Vid.push_back(dp);
     Vid.push_back(dm);
     Vid.push_back(d0h);
     Vid.push_back(d0l);
     Vid.push_back(dstp);
     Vid.push_back(dstm);
     Vid.push_back(ds0);
     Vid.push_back(ds0bar );
     Vid.push_back(dsp );
     Vid.push_back(dsm );
     Vid.push_back(dsstp );
     Vid.push_back(dsstm );
     Vid.push_back(ds0stp );
     Vid.push_back(ds0stm );
    
     bool flag=true;
     for(int i=0;i<Vid.size();i++){ if(xid == Vid[i]) return flag;}
     return false;
    }

    физика высоких энергий, китайский говнокод

    blah, 04 Июня 2012

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

    −29

    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
    template<class TValueChanger>
        NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger& ValueChanger)
        {
            return ValueChanger(Arc);
        }
    
        template<class TValueChanger>
        NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger& ValueChanger)
        {
            return ValueChanger(Line);
        }
    
    template<class TValueChanger1, class TValueChanger2>
        NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2)
        {
            return ValueChanger2(ValueChanger1(Arc));
        }
    
        template<class TValueChanger1, class TValueChanger2>
        NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2)
        {
            return ValueChanger2(ValueChanger1(Line));
        }
    
    //...
    
    template<class TValueChanger1, class TValueChanger2, class TValueChanger3, class TValueChanger4, class TValueChanger5, class TValueChanger6>
        NContour::NPrimitives::PArc ChangePrimitive(NContour::NPrimitives::PArc Arc, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2, const TValueChanger3& ValueChanger3, const TValueChanger4& ValueChanger4, const TValueChanger5& ValueChanger5, const TValueChanger6& ValueChanger6)
        {
            return ValueChanger6(ValueChanger5(ValueChanger4(ValueChanger3(ValueChanger2(ValueChanger1(Arc))))));
        }
    
        template<class TValueChanger1, class TValueChanger2, class TValueChanger3, class TValueChanger4, class TValueChanger5, class TValueChanger6>
        NContour::NPrimitives::PLine ChangePrimitive(NContour::NPrimitives::PLine Line, const TValueChanger1& ValueChanger1, const TValueChanger2& ValueChanger2, const TValueChanger3& ValueChanger3, const TValueChanger4& ValueChanger4, const TValueChanger4& ValueChanger5, const TValueChanger6& ValueChanger6)
        {
            return ValueChanger6(ValueChanger5(ValueChanger4(ValueChanger3(ValueChanger2(ValueChanger1(Line))))));
        }

    Говногость, 04 Июня 2012

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

    −28

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    command = QString("sh -c \"echo \"nameserver %1\" > /etc/resolv.conf\"")
                  .arg(nameserver.toString());
    
    QProcess process;
    process.start(command);

    Zielscheibe, 04 Июня 2012

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