1. Куча / Говнокод #14806

    +142

    1. 1
    Россия победила в XXII зимних Олимпийских играх.

    _Dark_, 23 Февраля 2014

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

    +36

    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
    #include <iostream>
    #include <cmath> 
    
    struct Point3D
    {
            float x,y,z;
            Point3D () {}
            Point3D (float x, float y, float z) : x(x), y(y), z(z) {}
            Point3D& operator -= (const Point3D& p) { x-=p.x; y-=p.y; z-=p.z; return *this; }
            Point3D operator - (const Point3D& p) const { Point3D p2(*this); return (p2-=p); }
            Point3D& operator *= (const float f) { x*=f; y*=f; z*=f; return *this; }
            Point3D operator * (const float f) const { Point3D p2(*this); return (p2*=f); }
    };
    
    float Dot (const Point3D& p1, const Point3D& p2) { return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z; }
    
    struct Face
    {
            Point3D            n;
            float              nc;
            float Dist (const Point3D& p) const { return Dot(p,n)-nc; }
    };
    
    int show_float(float src)
    {
            union
            {
                    int i;
                    float f;
            } u;
            u.f = src;
            return u.i;
    }
    
    float from_int(int src)
    {
            union
            {
                    int i;
                    float f;
            } u;
            u.i = src;
            return u.f;
    }
    
    template<typename T>
    T& operator<<(T& str, const Point3D& p)
    {
            str << std::hex << "Point3D(from_int(0x" << show_float(p.x) << "), from_int(0x" << show_float(p.y) << "), from_int(0x" << show_float(p.z) << "))";
            return str;
    }
    
    struct SPoint
    {
            Point3D p;
            bool DoCorrectFace(const Face& face)
            {
                    bool correct = true;
                    float j=1.0f;
                    Point3D np=p;
                    for (;;)
                    {
                            float ad = face.Dist(np);
                            if (ad<=0.0f)
                                    break;
                            correct=false;
                            np = p - (face.n*(ad*j));
                            j += 1.0f;
                    }
                    p=np;
                    return correct;
            }
    }; 
    
    using namespace std;
    int main()
    {
            cout << "Hello World!" << endl;
            SPoint spoint;
            spoint.p = Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0));
            cout << "Initial p:" << endl;
            cout << spoint.p << endl;
            cout << "Corrected:" << endl;
    
            Face f;
            f.n = Point3D(from_int(0x3d6cc83b), from_int(0x3f0e8841), from_int(0x3f5422bd));
            f.nc = from_int(0x41bac3dc); 
    
            bool result = spoint.DoCorrectFace(f);
            cout << spoint.p << endl;
            cout << "Done: " << result << endl;
            return 0;
    }

    говно в gcc
    g++ (rev5, Built by MinGW-W64 project) 4.8.1
    вывод в -O2 -DNDEBUG :

    Hello World!
    Initial p:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Corrected:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d1))
    Done: 0

    вывод в -O3 -DNDEBUG:

    Hello World!
    Initial p:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Corrected:
    Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
    Done: 0

    внимание вопрос: может ли быть такое, что DoCorrectFace не изменил точку ни на бит, но вернул false? В gcc может!

    TarasB, 23 Февраля 2014

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

    +50

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    CleverPtr(const int other) 
      {
        this->~CleverPtr();
        new(this) CleverPtr();
        //operator =(other); 
      }

    Решение крестопроблем в крестостиле гейдевщиков:
    http://ideone.com/wIPzzc

    LispGovno, 22 Февраля 2014

    Комментарии (29)
  4. JavaScript / Говнокод #14801

    +152

    1. 1
    $('<div />').html($title.html()).text();

    Нашел у себя, пытался вспомнить к чему данный финт ушами

    DrFreez, 22 Февраля 2014

    Комментарии (6)
  5. Python / Говнокод #14779

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    >>> max
    <built-in function max>
    >>> max.__call__
    <method-wrapper '__call__' of builtin_function_or_method object at 0x01D72080>
    >>> max.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D2730>
    >>> max.__call__.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D29B0>
    >>> max.__call__.__call__.__call__.__call__
    <method-wrapper '__call__' of method-wrapper object at 0x022D2970>
    >>> max.__call__.__call__.__call__.__call__(1,2,3)
    3

    We need to go deeper.

    Vindicar, 21 Февраля 2014

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

    +57

    1. 1
    for(int loshdka_skachi = 0; loshadka_skachi < pyati_raz; loshadka_skachi += prig_skok){

    оттуда
    конардо посвящается

    LispGovno, 21 Февраля 2014

    Комментарии (30)
  7. JavaScript / Говнокод #14772

    +155

    1. 1
    <form onsubmit="return true && checkXML(name)">

    и причем здесь true

    dead_star, 21 Февраля 2014

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

    +46

    1. 1
    2. 2
    3. 3
    4. 4
    vector<int> v = {1, 4, 6};
    cout << "(";
    copy(v.begin(), v.end(), ostream_iterator<int>(cout, ", "));
    cout << ")";

    http://ideone.com/2j2jQG

    LispGovno, 21 Февраля 2014

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

    +41

    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
    for (std::vector<SomeClass::SmartPtr>::iterator i = candidates.begin ();
               i != candidates.end (); )
          {
             if ((*i)->getArea ().intersect (thisArea))
             {
                // label is inside the area.
                ++i;
             }
             else
             {
                // label must be removed
                std::iter_swap (i, candidates.end () - 1);
                candidates.pop_back ();
             }
          }

    Не совсем ясны были мотивы человека, написавшего это. Этот код вообще не работает и не сразу и поймешь что тут к чему.

    bes, 21 Февраля 2014

    Комментарии (7)
  10. PHP / Говнокод #14763

    +149

    1. 1
    $->db->select_value('select now()');

    наверное в мускуле какое-то другое время

    dead_star, 21 Февраля 2014

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