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

    +997

    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
    82. 82
    class fileOutBuf : public streambuf
    {
    public:
        // ...
        typedef char        char_type;
        typedef int         int_type;
        typedef int         streamsize;
        // ...
        int printf( const char * fpFormat, ... );
    
        inline int vprintf( const char * fpFormat, va_list fvaList )
        {
            if ( NULL != dpFileDescriptor )
            {
                if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                    vfprintf( dpVerboseFileDescriptor, fpFormat, fvaList );
    
                return vfprintf( dpFileDescriptor, fpFormat, fvaList );
            }
            else
            {
                if ( NULL != dpOutputFuncPtr )
                    return (*dpOutputFuncPtr)( fpFormat, fvaList );
            }
            return 0;
        }
        // ....
        virtual int_type overflow( int_type c = EOF );
        virtual streamsize xsputn( const char_type *s, streamsize n );
        // ....
    };
    
    int fileOutBuf::printf( const char * fpFormat, ... )
    {
        va_list lvaList;
        int lRet;
    
        va_start( lvaList, fpFormat );
    
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                vfprintf( dpVerboseFileDescriptor, fpFormat, lvaList );
    
            lRet = vfprintf( dpFileDescriptor, fpFormat, lvaList );
        }
        else
        {
            if ( NULL != dpOutputFuncPtr )
                lRet = (*dpOutputFuncPtr)( fpFormat, lvaList );
        }
    
        va_end( lvaList );
    
        return lRet;
    }
    
    fileOutBuf::int_type fileOutBuf::overflow( int_type c )
    {
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                fputc( c, dpVerboseFileDescriptor );
    
            return fputc( c, dpFileDescriptor );
        }
        else
            return fileOutBuf::printf( "%c", c );
    }
    
    fileOutBuf::streamsize fileOutBuf::xsputn( const fileOutBuf::char_type *s, fileOutBuf::streamsize n )
    {
        if ( NULL != dpFileDescriptor )
        {
            if ( true == sdVerboseFlag  && false == dSkipVerboseOutput)
                fwrite( s, sizeof( char_type ), n, dpVerboseFileDescriptor );
    
            return fwrite( s, sizeof( char_type ), n, dpFileDescriptor );
        }
        else
            return fileOutBuf::printf( "%*s", n, s );
    }

    нетривиальная капипаста или делаем из мухи слона.

    ЗЫ после удаления всей капипасты, от класа в целом осталось что-то около 50 строк.

    Dummy00001, 06 Декабря 2011

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

    +1002

    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
    BOOLEAN ConvertSizeToStr(__int64 size,TCHAR *buf,DWORD buf_size_c)
    {
       double dsize;
       HRESULT hr;
     
       dsize=(double)size;
       if (size/1500000000000L>0) 
       {
          dsize/=1099511627776L;
          hr=StringCchPrintf(buf,buf_size_c,_T("%.2lf Тб"),dsize);
       }
       else if (size/1500000000L>0) 
       {
          dsize/=1073741824L;
          hr=StringCchPrintf(buf,buf_size_c,_T("%.2lf Гб"),dsize);
       }
       else if (size/1500000L>0) 
       {
          dsize/=1048576L;
          hr=StringCchPrintf(buf,buf_size_c,_T("%.2lf Мб"),dsize);
       }
       else if (size/1500>0) 
       {
          dsize/=1024;
          hr=StringCchPrintf(buf,buf_size_c,_T("%.2lf Кб"),dsize);
       }
       else
          hr=StringCchPrintf(buf,buf_size_c,_T("%I64d байт"),size);
     
       if (SUCCEEDED(hr))
          return true;
       else
          return false;
     
    }

    Конвертировать байты в КБ/МБ/ГБ

    azote, 05 Декабря 2011

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

    +168

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    case IDC_LED1_ZERO:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_ZERO) )
    				{
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
    						::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_ZERO,0);
    					::CheckDlgButton(hWnd,IDC_LED3_ZERO,0);
    					::CheckDlgButton(hWnd,IDC_LED4_ZERO,0);
    
    				}
    		break;
    		case IDC_LED1_ANYSPEED:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_ANYSPEED) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
    						::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_ANYSPEED,0);
    					::CheckDlgButton(hWnd,IDC_LED3_ANYSPEED,0);
    					::CheckDlgButton(hWnd,IDC_LED4_ANYSPEED,0);
    				}
    		break;
    		case IDC_LED1_POSITION:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_POSITION) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED2_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED3_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED4_POSITION,0);
    
    				}
    		break;
    		case IDC_LED1_TURN_UNDER:
    				if (::IsDlgButtonChecked (hWnd,IDC_LED1_TURN_UNDER) )
    				{
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
    						::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
    
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
    						::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
    					
    					if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) || 
    						::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
    						::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
    
    					::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
    					::CheckDlgButton(hWnd,IDC_LED2_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED3_TURN_UNDER,0);
    					::CheckDlgButton(hWnd,IDC_LED4_TURN_UNDER,0);
    				}

    Понадобилось добавить ещё один чек бокс. Зашёл в обработчик - а там такое. И это только начало, всё не поместилось. Чтобы представить масштабы скажу, что чекбоксов 16..., я должен добавить ещё 4.

    slavap, 04 Декабря 2011

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

    +1000

    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
    bool __fastcall TItsString::operator == (const char* sVal) const
    {
      bool Empty1 = ((FStringValue == NULL) || (FStringValue[0] == 0));
      bool Empty2 = ((sVal == NULL) || (sVal[0] == 0));
      if (Empty1 && Empty2) return true;
      if (Empty1 || Empty2) return false;
      int i,j,k;
      for(i=0; FStringValue[i] && (GET_LOWER_CHAR(FStringValue[i]) == GET_LOWER_CHAR(sVal[i])); i++);
      if ((FStringValue[i] == 0) && (sVal[i] == 0)) return true;
      j=i; k=i;
      if (sVal[k] == 0)  for(; FStringValue[i] == 0x20; i++);
      if (FStringValue[k] == 0) for(; sVal[j] == 0x20; j++);
      if ((FStringValue[i] == 0) && (sVal[j] == 0)) return true;
      return false;
    }

    Try, 03 Декабря 2011

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

    +1020

    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
    #include <stdio.h>
    #define _0000 0
    #define _0001 int
    #define _0010 a
    #define _0011 16
    #define _0100 b
    #define _0101 c
    #define _0110 printf
    #define _0111 "%d"
    #define _1000 d
    #define _1001 (
    #define _1010 )
    #define _1011 =
    
    int main()
    {
    	_0001 _1000 _1011 _0011;
    	_0001 _0010 _1011 _1000;
    	_0001 _0100 _1011 _1001--_1000 _1010+++_1001++_1000 _1010;
    	_0001 _0101 _1011 _0010>_0100?_0010:_0100>_0010?_0100:_0000;
    	_0110 _1001 _0111, _0101 _1010;
    	getchar();
    }

    Показал первому курсу define, на дом задал простейшую задачу. На следующий день увидел это.

    A1mighty, 01 Декабря 2011

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

    +993

    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
    class A
    {
    public:
     int a;
     int getA(){return a;}
    };
    
    class B: public A
    {
    public:
     int b;
     int getB(){return b;}
    };
    
    class C: public A
    {
    public:
     int c;
     int getC(){return c;}
    };
    
    class D: public C, public B
    {
    public:
     D(): d(0) {}
     int d;
     int getD(){return d;}
    };
    
    int main()
    {
     D d;
     std::cout << d.getD();
    }

    Знакомый программист утверждает, что этот пример является примером "возможности ромбовидного наследования" в С++, совсем забывая, что этот замечательный язык генерирует ромбовидное наследование только при наследовании виртуальном, а пример не раскрывает проблему и наполовину.

    ololo_trololo, 01 Декабря 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    AnsiString DateArray = "";
    int DaysBetween = 0;
    DaysBetween = DateTimePicker2->Date - DateTimePicker1->Date;
    for (int i = 0; i <= DaysBetween; i++ )
    {
     if (i != 0)
     DateArray = DateArray + " OR ";
     DateArray =  DateArray + " date_made = '"+DateToStr(DateTimePicker1->Date + i)+"'";
    }

    Очевидно, подготавливаем запрос для отбора по диапазону дат :)

    labutinpa, 29 Ноября 2011

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

    +1001

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    QStringList list;
    QStringList::iterator i, j;
    //...
    i = qLowerBound(list.begin(), list.end(), value);
    j = qUpperBound(list.begin(), list.end(), value);
    while (i != j) {
    	processItem(*i);
    	++i;
    }

    Пахучее пятнышко из брошюры "Qt 4's Generic Algorithms"

    Xom94ok, 27 Ноября 2011

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

    +146

    1. 1
    for (int i=0, N=sizeof(a)/sizeof(int); ++i<N-1; s+=(int)(a[i]>a[i-1]&&a[i]>a[i+1]));

    Это говнокод или годный троллинг? Топик http://forum.codenet.ru/threads/69046-Помогите-задача-С/

    mrxak, 22 Ноября 2011

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

    +1015

    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
    GetScreenShot()
    {
      std::string NameScreen = ToString(GameLevel->EngineName) + "_" + ToString(GTime->GetTimeDays()) + "_" + ToString(GTime->GetTimeHours()) + "_" + ToString(GTime->GetTimeSec()) + ".bmp";
    
      IDirect3DTexture9 *tex;
      IDirect3DSurface9 *surf;
      D3DVIEWPORT9 vp;
    
      Device->GetViewport(&vp);
        if FAILED(Device->CreateTexture(vp.Width, vp.Height, 1, 0, D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM, &tex, NULL ))
          Beep(1000,100);
        
        if FAILED(tex->GetSurfaceLevel(0, &surf))
          Beep(500,100);
        if FAILED(Device->GetFrontBufferData(0, surf)) 
          Beep(200,100);
        D3DXSaveSurfaceToFile(ToPointChar(ToString(Pather::CutPath()) + "\\ScreenShots\\" + NameScreen), D3DXIFF_BMP, surf, NULL, NULL);
      surf->Release();
      tex->Release();
    }

    http://www.gamedev.ru/code/forum/?id=154941

    dos_, 20 Ноября 2011

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