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

    +166

    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
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    void sort(student x[], perech *&py)
         { int l;
           perech t;
           //perech *y;
           py=new perech[n];
           l=1; k=0;
           for(i=0; i<n; i++)
    	  { fl=0;
    	    for(j=0; j<l; j++)
    	       { if((strcmp(x[i].fam,py[j].fam)==0)&&((strcmp(x[i].im,py[j].im)!=0)||(strcmp(x[i].gr,py[j].gr)!=0)))
    		   { fl=1;
    	    py[j].ng++; break;
    		   }
    		 if(fl==0) { strcmp(py[l-1].fam,x[i].fam);
    			     py[l].ng=1; l++;
    			   }
    	       }
    	  }
           for(i=0; i<(l-1); i++)
    	  for(j=i+1; j<l; j++)
    	     if(py[i].ng<py[j].ng)
    	       { t=py[i];
    		 py[i]=py[j];
    		 py[j]=py[i];
    	       }
           for(i=1; i<l; i++)
    	  if(py[0].ng=py[i].ng)
    	    k++;
           k++;
           py=new perech[k];
           if(py==NULL) {
    		      cout<<"Net pamyati"; getch();
    		      k=0; delete []py; return;
    		    }
           for(i=0; i<l; i++)
    	  py[i]=py[i];
           delete []py;
           cout<<"Perechen' sformirovan:\n";
           getch();
           for(i=0; i<l; i++)
    	  cout<<py[i].fam<<" "<<py[i].ng<<endl;
           getch();
         }
    void outputFileStudent(perech x[])
         { int l;
           ofstream fout;
           char file[L];
           cout<<"Vvedite imya faila:\n"; cin>>file;
           fout.open(file);
           if(fout.fail()) { cout<<"Error... Press any key for exit";
    			 getch(); return;
    		       }
           for(i=0; i<l; i++)
    	  fout<<x[i].fam<<" "<<x[i].ng<<endl;
           cout<<"File save\n";
           getch();
         }
    void outputFileStudentBin(perech y[])
         { ofstream fout;
           char file[L];
           cout<<"Vvedite imya save fila:\n"; cin>>file;
           fout.open(file, ios::binary);
           if(fout.fail()) { cout<<file<<"ne sozdan\n"; getch(); return; }
           fout.write((char *) y, k*sizeof(perech()));
           if(fout.fail()) { cout<<"Oshibka zapisi\n"; getch(); return; }
           cout<<"Perechen save\n";
           getch();
           fout.close();
         }
    void inputFileStudentBin(perech *&px)
         { ifstream fin;
           char file[20];
           int l;
           perech t;
           cout<<"Vvedite imya save faila:\n"; cin>>file;
           fin.open(file);
           if(fin.fail()) { cout<<"Error\n"; getch(); return();}
           for(i=0; i<l; i++)
    	   fin>>t.fam>>t.ng;
           fin.close();
    
           if(px!=NULL) delete []px;
           fin.open(file);
           if(fin.fail()) { cout<<"Povtornaya oshibka\n"; getch();
    			delete []px; k=0; return; }
           for(i=0; i<k; i++)
    	  fin>>px[i].fam>>px[i].ng;
           cout<<"file vveden\n"; getch();
           for(i=0; i<l; i++)
    	  cout<<px[i].fam<<" "<<px[i].ng<<endl;
           getch();
           fin.close();
         }

    Новый стажер решил задачу про студентов, вызывая их в компилированном виде из модуля 1С.
    Не знал в какой раздел запостить, поэтому пощу в 1С
    Вообще-то в 1С своя база.

    alexoy, 10 Октября 2011

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

    +160

    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
    class array
    {
        int data[256];
        int p;
    
    public:
        array ():
            p (0)
        {}
    
        array & operator , (int a)
        {
            data[p++] = a;
            return *this;
        }
    
        array & operator = (const array & arr)
        {
            p = 0;
            memcpy (data, arr.data, sizeof (data));
            return *this;
        }
    
        int & operator [] (size_t i)
        {
            return data[i];
        }
    };
    
    #define _I array(),
    #define I_
    #define o_O ,
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        array arr;
        arr = _I 1,2,3,4,5,6 I_;    // init
        arr o_O 7,8,9,10;           // append new
        arr o_O 11 o_O 12;          // append new
    }

    http://www.gamedev.ru/flame/forum/?id=153265#m4

    RS-232, 09 Октября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    const static int m=5, n=5;
    int matrix[m][n];
    cout << 1[2[matrix]];

    Пруй:

    http://ideone.com/bO5Gn

    RS-232, 09 Октября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    int *inter = (int[]){1, 8}; 
      /*...*/ 
      inter = (int[]){8, 9};

    RS-232, 08 Октября 2011

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    auto L = [](int i)->int { return i+1; };
    typedef decltype(L) TL;
    auto lfunc = &TL::operator();
    int i = (L.*lfunc)(1);

    ohlol, 08 Октября 2011

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

    +160

    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
    #include <iostream>
     
    int main()
    {
    int a[4] = {1,2,3,4}; 
    int (&b)[4] = a; 
    int c[4] = {5,6,7,8}; 
    a=c; 
    std::cout<<b[0];
    }
    
    prog.cpp: In function ‘int main()’:
    prog.cpp:8: error: invalid array assignment

    Да, похоже С++ не настолько высокоуровневый, чтобы поддерживать такое понятие как присваивание массивов.

    http://www.gamedev.ru/flame/forum/?id=153265&page=2#m20

    TarasB, 08 Октября 2011

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

    +157

    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
    #include <iostream>
    #include <boost/mpl/pair.hpp>
    #include <boost/mpl/key_type.hpp>
    #include <boost/mpl/map.hpp>
    #include <boost/mpl/string.hpp>
    #include <boost/mpl/for_each.hpp>
    using namespace boost;
    typedef mpl::map<
       mpl::pair<mpl::string<'H','e','l','l','o'>, mpl::int_<0>>,
       mpl::pair<mpl::string<',',' '>, mpl::int_<1>>,
       mpl::pair<mpl::string<'W','o','r','l','d','!'>, mpl::int_<2>>
    > map;
    struct do_some {
       template<typename T>
       void operator()(T) const {
          std::cout << mpl::c_str<T>::value;
       }
    };
    int main() {
       mpl::for_each<
          map,
          typename mpl::lambda<
             mpl::key_type<map, mpl::_1>
          >
       >(do_some());
    }

    еще один хеловорд.

    niXman, 08 Октября 2011

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

    +154

    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
    class Allocator
    {
    public:
      
      virtual void *Alloc (size_t) = 0;
      virtual void Dealloc (void *) = 0;
    
      struct Allocation
      {
        Allocator *m_pAllocator[1];
    
        static void Dealloc (void *ptr)
        {
          if (ptr)
            ((Allocator **)ptr)[-1]->Dealloc (((Allocator **)ptr)-1);
        }
      };
    };
    
    class UsesAllocator
    {
    public:
      void *operator new (size_t aSize,Allocator &aAllocator)
      {
        Allocator::Allocation *pResult =
          (Allocator::Allocation *)
          aAllocator.Alloc (aSize+sizeof (Allocator::Allocation));
        if (!pResult) throw std::bad_alloc ();
        pResult->m_pAllocator[0] = &aAllocator;
        return pResult->m_pAllocator+1;
      }
    
      void *operator new [] (size_t aSize,Allocator &aAllocator)
      {
        Allocator::Allocation *pResult =
          (Allocator::Allocation *)
          aAllocator.Alloc (aSize+sizeof (Allocator::Allocation));
        if (!pResult) throw std::bad_alloc ();
        pResult->m_pAllocator[0] = &aAllocator;
        return pResult->m_pAllocator+1;
      }
    
      void operator delete (void *ptr,Allocator &)
      { Allocator::Allocation::Dealloc (ptr); }
    
      void operator delete (void *ptr)
      { Allocator::Allocation::Dealloc (ptr); }
    
      void operator delete [] (void *ptr,Allocator &)
      { Allocator::Allocation::Dealloc (ptr); }
    
      void operator delete [] (void *ptr)
      { Allocator::Allocation::Dealloc (ptr); }
    };
    ...
    
    class MyClass: /*virtual*/ public UsesAllocator
    {
    public:
      ...
    };
    ...
    MyClass *PROFIT = new (allocatorOfOurInterest) MyClass (...);

    http://www.gamedev.ru/flame/forum/?id=153274

    >Посоны! Оказывается, оператор new можно перегружать!

    ohlol, 08 Октября 2011

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

    +167

    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
    #define BREAKABLE_SECTION() for(;;)
    
    BREAKABLE_SECTION()
    {
        ::Packet * pPacket;
        res = ReadPacket(pPacket);
    
        if(ERR_OK == res)
        {
            res = pConstructor->PutPacket(pPacket);
    
            if(ERR_OK == res)
            {
                res = pConstructor->GetFrame(data);
            }else
            {
                //TODO:add handler of statuses other than err_ok
            }
    
            if (ERR_OK ==res)
            {
                break;
            }else
            {
                //TODO:add handler of statuses other than err_ok
            }
        }else
        {
            break;
        }
        break;
    }

    перешел в новый проект где предложили изучить существующий код в огромном объеме - а он весь из таких циклов

    openclgovno, 06 Октября 2011

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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    if ((intPas1Sel == 1) && (intMode11+intMode12    > 0)) { tgt [tgtNum].c1=tgtCode [prTgt [j].Num][0]; h2=h2 | 0x800 ; h1=h1 | (s << 12); }
    			if ((intPas2Sel == 1) && (intMode2               > 0)) { tgt [tgtNum].c3=tgtCode [prTgt [j].Num][1]; h2=h2 | 0x1000; h1=h1 | (s << 10); }
    			if ((intPas3ASel== 1) && (intMode3A1+intMode3A2  > 0)) { tgt [tgtNum].c3=tgtCode [prTgt [j].Num][2]; h2=h2 | 0x2000; h1=h1 | (s << 8 ); }
    			if ((intSecOver == 0) && (prTgt [j].unStateIdent > 0)) { tgt [tgtNum].cc=tgtCode [prTgt [j].Num][3]; h2=h2 | 0x8000; h1=h1 | (s << 14); }

    Так форматируют код профессионалы в нашей фирме

    russian_avionics, 04 Октября 2011

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