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

    +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
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    const Tifon& Tifon::operator=(const Tifon& Buffer)
    {
            assert(&Buffer!=this);
            if(&Buffer==this)
                    return *this;
            Tifon OldForExceptionSafe(*this);
            try{
                    this->~Tifon();
                    ::new((void*)this)Tifon(Buffer);
            }catch(...){//try restore
                    ::new((void*)this)Tifon(OldForExceptionSafe);
            }
            return *this;
    };
     //...
    namespace std
    {
            const Tifon&swap (Tifon& a, Tifon& b) {
            assert(&a!=&b);
            if(&a==&b)
                    return a;
            Tifon c(a);
            a=b;
            b=c;
            }
    };

    USB, 22 Июля 2012

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

    +7

    1. 1
    2. 2
    QRegion* region = new QRegion(*(new QRect(button->x()+5,button->y()+5,190,190)),QRegion::Ellipse);
    button->setMask(*region);

    panter_dsd, 22 Июля 2012

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

    +3

    1. 1
    x*x = new x;

    Уравнение?

    USB, 21 Июля 2012

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    int i=0;
            for (;i<5;
                 printf("%d",i);
                 i++;
                 );

    ZevsVU, 17 Июля 2012

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

    +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
    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
    InputMapping* GetInputMapping(unsigned int index)
        {
            InputMapping* inputMapping = NULL;
    
            switch (index)
            {
                // Movement
            case 0:
                return &m_LeftStickMapping[InputBindings::StickDirUp];
            case 1:
                return &m_LeftStickMapping[InputBindings::StickDirDown];
            case 2:
                return &m_LeftStickMapping[InputBindings::StickDirLeft];
            case 3:
                return &m_LeftStickMapping[InputBindings::StickDirRight];
    
                // Actions
            case 4:
                return &m_ButtonMappings[Pad::ShoulderRight1];
            case 5:
                return &m_ButtonMappings[Pad::Button2];
            case 6:
                return &m_ButtonMappings[Pad::Button4];
            case 7:
                return &m_ButtonMappings[Pad::Button3];
            case 8:
                return &m_ButtonMappings[Pad::Button1];
    
                // Weapons
            case 9:
                return &m_ButtonMappings[Pad::PadLeft];
            case 10:
                return &m_ButtonMappings[Pad::PadUp];
            case 11:
                return &m_ButtonMappings[Pad::PadRight];
            case 12:
                return &m_ButtonMappings[Pad::PadDown];
            case 13:    // weapon wheel
                return &m_ButtonMappings[Pad::ShoulderRight2];
    
                // Camera
            case 14:
                return &m_RightStickMapping[InputBindings::StickDirUp];
            case 15:
                return &m_RightStickMapping[InputBindings::StickDirDown];
            case 16:
                return &m_RightStickMapping[InputBindings::StickDirLeft];
            case 17:
                return &m_RightStickMapping[InputBindings::StickDirRight];
            case 18:
                return &m_ButtonMappings[Pad::ShoulderLeft1];
            case 19:
                return &m_ButtonMappings[Pad::ShoulderLeft2];
            case 20:
                return &m_ButtonMappings[Pad::StickRight];
    
                // Menus
            case 21:
                return &m_ButtonMappings[Pad::Select];
            case 22:
                return &m_ButtonMappings[Pad::Start];
    
                // First-person camera
            case 23:
                return &m_ButtonMappings[Pad::StickLeft];
            default:
                return NULL;
            }
            return NULL;
        }

    Массивы? Не, не слышал.

    bazhenovc, 17 Июля 2012

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

    +20

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void File::open(string file, bool readAccess, bool writeAccess, bool append)
    {
    	Close();
    	(string&)Name=file;
    	const char* const modes[2][2][2]={{{null, "rb"}, {"wb", "w+b"}}, {{null, null}, {"ab", "a+b"}}};
    	if(modes[append][writeAccess][readAccess]==null) return InternalError("Создание файла с неверными параметрами!");
    	handle=fopen(Name.CStr(), modes[append][writeAccess][readAccess]);
    	if(handle==null) throw NotFoundException(string::Format("Файл <^> не найден!")(file));
    }

    Скорее всего, этот код вам покажется странным, поэтому я его выкладываю. Хотя я его говнокодом не считаю и он мне даже нравится.

    gammaker, 16 Июля 2012

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

    +31

    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
    #include <iostream>
    using namespace std;
    
    struct RefStruct {
        RefStruct(int &ref) :
            m_ref(ref)
        {}
        
        int getRefValue() const {
            return m_ref;
        }
    
    private:
        int &m_ref;
    };
    
    int main(int argc, char *argv[]) {
        int a = 0xa;
        int b = 0xb;
    
        RefStruct s(a);
        RefStruct *p = &s;
        
        *(reinterpret_cast<int **>(p)) = &b;
        
        cout << "RefValue: " << hex << s.getRefValue() << endl;
    
        return 0;
    }

    С другом разговаривали - как бы получить указатель на ссылку.

    Как вы думаете, что будет на выхлопе?

    Elvenfighter, 15 Июля 2012

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

    +32

    1. 1
    2. 2
    3. 3
    4. 4
    typedef typename _STD tr1::conditional<
            _STD tr1::is_same<key_type, value_type>::value,
            const_iterator,
            _Tree_iterator<_Mybase> >::type iterator;

    Шаблоны на шаблонах и шаблонами погоняют.

    Fai, 14 Июля 2012

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

    +24

    1. 1
    2. 2
    3. 3
    Fixed f = 0.2;
    	f = std::abs(f);
    	std::cout << (float)f;

    Угадайте, чему будет равно f?
    Fixed - тип из той же библиотеки, что и в http://govnokod.ru/11294

    TarasB, 10 Июля 2012

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

    +24

    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
    do
        {
    		count++;
    		Xt=X;
    		if (ii==1)
    		{
    			X= dichotomia(a,b, E);
    			fprintf(bnf, "%lf;\n", Xt);
    		}
    		else
    		{
    			if (ii==2)
    			{
    				X=newton(X, E);
    				fprintf(bnf, "%lf;\n", Xt);
    			} 
    			else
    			{
    				if (ii==3)
    				{
    					X=sekuschich(X, b);
    					fprintf(bnf, "%lf;\n", Xt);
    				}
    				else
    				{
    					if (ii==4)
    					{
    						ii==1;
    						ii==2;
    						ii==3;
    					}
    				}
    			}
    		}
    		printf("X=%lf\n", X);
    		if(Func(X)*Func(a)>0)a=X;
    		else b=X;
    	}
    	while(fabs(X-Xt)>=E);

    В общем лаба на численые методы поиска корней.
    После того как я предоставил няшный, полностью удовлетворяющий условиям, после проверки меня попросили "сделать как у парней", и вот участок их высера

    p.s. форматирование сохранить не удалось, да и там совсем бы ничего понятно бы не было

    maksim_ovcharik, 09 Июля 2012

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