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

    +6

    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 <iostream>
    
    using std::cout;
    using std::endl;
    
    auto power(double x, int n)-> double*;
    
    int main()
    {
    	void * c = power(5,2);
    
    	std::cout << *(double*)c << std::endl;
    
    	return 0;
    }
    
    auto power(double x, int n)-> double* 
    { 
    	double* result(new double(1.0));
    	for(int i = 1; i <= n; i++)
    	*result *= x;
    	return result;
    }

    taburetka, 21 Августа 2013

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

    +9

    1. 1
    // When F does not contain result_type, result_of<F(T1, T2, ..., TN)>::type is F::result<F(T1, T2, ..., TN)>::type when N > 0 or void when N = 0.

    http://www.boost.org/doc/libs/1_54_0/libs/utility/utility.htm#result_of
    > void when N = 0.
    Создатели boost::result_of решили, что если функция принимает 0 аргументов, то она не может ничего возвращать кроме void.

    LispGovno, 20 Августа 2013

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

    +20

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Matrix matrix ( h, w );
    delete &h, &w;
    
    for ( int i = 0; i < h; i++ )
    {
        for ( int j = 0; j < w; j++ )
        {
            cout << "Введите элемент [" << i << ", " << j << "]: ";
            cin >> matrix[i][j];
        }
    }

    Найди ошибку...

    SkaN, 19 Августа 2013

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

    +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
    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
    #include <iostream> 
     #include <conio.h> 
     #include <math.h> 
     using namespace std; 
    
     int main() 
     { 
     setlocale(0,"Russian"); 
     cout<<"Пишиш без a,b,c,приклад: 2 5 -12 або натиснеш на Enter и пишеш вниз,"<<endl; 
     cout<<"ПИШИ:"<<endl; 
     float D; 
     int repetare=0; 
     int a; 
     int b; 
     int c; 
     int x1; 
     int x2; 
     repetare; 
     { 
     while(repetare<100) 
     { 
     cout<<"a="; 
     cin>>a; 
     cout<<"b="; 
     cin>>b; 
     cout<<"c="; 
     cin>>c; 
     D=(b^2-(4*a*c))*(-1); 
     x1=(b-sqrt(D))/(2*a); 
     x2=(b+sqrt(D))/(2*a); 
     if (D>0) 
     { 
     cout<<"D="<<D<<endl; 
     cout<<"x1="<<x1<<endl; 
     cout<<"x2="<<x2<<endl; 
     cout<<"Имеет два кореня"<<endl; 
     } 
    
    
     if (D<0) 
     { 
     cout<<"D="<<D<<endl; 
     cout<<"Не имеет кореней"<<endl; 
     } 
     if(D=0) 
     { 
     cout<<"D="<<D<<endl; 
     cout<<"x1="<<x1<<endl; 
     cout<<"Имеет один корень"<<endl; 
     } 
     repetare++; 
     } 
     } 
     getche(); 
     return 0; 
     }

    С одного из сайтов игроделов. Просто оставлю это здесь

    pelmenka, 16 Августа 2013

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

    +83

    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
    typedef map<string,string> keys_map;
    ...
    const keys_map::const_iterator SectionData::operator[](int Index) const
    {                                                                     
            keys_map::const_iterator it=m_Keys.begin();                   
            int cnt=0;
            for(;it!=m_Keys.end(); it++)                                  
            {
                    if(cnt==Index)                                        
                            return it;                                    
                    cnt++;  
            }       
            return (keys_map::const_iterator)NULL;                        
    }
    ...
    SectionData section;
    keys_map::::const_iterator iter;
    for (i=0; i<section.GetSize(); i++) {
            iter = section[i];
            ...
    }

    правильный способ итерироваться по мапу

    gpr, 16 Августа 2013

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

    +77

    1. 1
    float tlen = sqrtf(top[0]*top[0]+top[1]*top[1]+top[2]*top[2]);

    Всё в мире тлен и безысходность. В том числе и код.

    Sauron, 10 Августа 2013

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

    +15

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    union AtomicIndx
    {
      struct { std::atomic<uint16> ReadCur, ReadMax, WriteCur, WriteMax; };
      struct { struct Idx { uint16 Cur, Max; }; std::atomic<Idx> Read, Write; };
      struct { struct Idx { uint16 ReadCur, ReadMax, WriteCur, WriteMax; }; std::atomic<Idx> All; };
    };
    static_assert(sizeof(AtomicIndx) == sizeof(uint64), "sizeof(AtomicIndx) != sizeof(uint64)");

    Мы все знаем откуда это.

    LispGovno, 08 Августа 2013

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

    +20

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    template<class T> 
    void FuncSmth(T value) 
    { 
      if(typeid(T) == typeid(int)) 
          FuncInt(value); 
      else if(typeid(T) == typeid(char*)) 
          FuncCharPtr(value); 
    }

    Оттуда

    falsting, 06 Августа 2013

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

    +21

    1. 1
    typedef void *(*internalPointer) (const std::map<std::string, std::pair<const void*  volatile* const, void* const *> > (*FuncPointer)(volatile const int&, const char *const, const void *const *const (*FuncArg)(const std::vector<std::string>&)), void * const *, volatile int&, int * (*FuncArg2) (const std::string&, const std::vector<void>*) );

    thereisnosun, 06 Августа 2013

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

    +12

    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
    if  ( (_gen_statP==tm_Manual)  ||
                              (_gen_statP==tm_OK)          && (_cur_statP!=tm_Manual)  ||
                              (_gen_statP==tm_ValidTM)     && (_cur_statP!=tm_Manual)  &&  (_cur_statP!=tm_OK) ||
                              (_gen_statP==tm_Rejected)    && (_cur_statP!=tm_Manual)  &&  (_cur_statP!=tm_OK) && (_cur_statP!=tm_ValidTM) ||
                              (_gen_statP==tm_Bad)         && (_cur_statP!=tm_Manual)  &&  (_cur_statP!=tm_OK) && (_cur_statP!=tm_ValidTM) && (_cur_statP!=tm_Rejected) ||
                              (_gen_statP==tm_Statistic)   && (_cur_statP!=tm_Manual)  &&  (_cur_statP!=tm_OK) && (_cur_statP!=tm_ValidTM) && (_cur_statP!=tm_Rejected)  && (_cur_statP!=tm_Bad)
                            ) {
                                _cur_statP = _gen_statP;
                              }
    
    
                        if  ( (_gen_statQ==tm_Manual)  ||
                              (_gen_statQ==tm_OK)          && (_cur_statQ!=tm_Manual) ||
                              (_gen_statQ==tm_ValidTM)     && (_cur_statQ!=tm_Manual) && (_cur_statQ!=tm_OK) ||
                              (_gen_statQ==tm_Rejected)    && (_cur_statQ!=tm_Manual) && (_cur_statQ!=tm_OK) && (_cur_statQ!=tm_ValidTM) ||
                              (_gen_statQ==tm_Bad)         && (_cur_statQ!=tm_Manual) && (_cur_statQ!=tm_OK) && (_cur_statQ!=tm_ValidTM) && (_cur_statQ!=tm_Rejected) ||
                              (_gen_statQ==tm_Statistic)   && (_cur_statQ!=tm_Manual) && (_cur_statQ!=tm_OK) && (_cur_statQ!=tm_ValidTM) && (_cur_statQ!=tm_Rejected)  && (_cur_statQ!=tm_Bad)
                            ) {
                                _cur_statQ = _gen_statQ;
                              }

    Вроде работает, но уж больно некрасиво) по идее вычисляет новый статус в соответствии с "приоритетом"

    mapron, 06 Августа 2013

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