1. Лучший говнокод

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. C++ / Говнокод #13203

    +20

    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
    #include <iostream>
    
    enum Quiet { LOG };
    
    template<typename T>
    Quiet operator <<(Quiet o, T) {
        return o;
    }
    
    static inline Quiet operator <<(Quiet o, std::ostream &(*)(std::ostream &)) {
        return o;
    }
    
    int main() {
        LOG << "Hello world!" << std::endl;
        return 0;
    }

    Измыслил сегодня вот такую вот затычку для выключения логгирования

    uranix, 20 Июня 2013

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

    +20

    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
    #include <iostream>
    #include <cstring>
    
    const char tag[] = "Secret tag!";
    const size_t tagSize = sizeof(tag);
    const size_t nameSize = 32;
    
    template<class T>
    struct Value
    {
        Value(const char* name, const T& data) :
    data(data)
    {
        std::strncpy(this->tag, ::tag, tagSize);
        std::strncpy(this->name, name, nameSize);
    }
    char tag[tagSize];
    char name[nameSize];
    T data;
    };
    
    int getStackDir()
    {
        char a;
        char b;
        return &b > &a ? 1 : -1;
    }
    
    template<class T>
    T getValue(const char* name)
    {
        static const size_t stackSize = 1024 * 1024;
        const int stackDir = getStackDir();
        char begin;
        for(char* p = &begin, *end = &begin - stackSize * stackDir; p != end; p -= stackDir)
        {
            Value<T>* value = (Value<T>*)p;
            if(std::strcmp(value->tag, tag) != 0) continue;
            if(std::strcmp(value->name, name) != 0) continue;
            return value->data;
        }
        return T();
    }
    
    #define SET(type, name, value) Value<type> name(#name, value)
    #define GET(type, name) getValue<type>(#name)
    
    //-----------------------------------------------------------
    
    void test()
    {
        std::cout << GET(int, x) << std::endl;
    }
    
    int main()
    {
        SET(int, x, 13);
        test();
    }

    Отсюда http://www.rsdn.ru/forum/cpp/5163916.flat#5163916

    Artur, 13 Мая 2013

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

    +20

    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
    #include <iostream>
    #include <string>
    #include <utility>
    #include <tuple>
    #include <array>
    #include <vector>
    #include <algorithm>
    #include <iterator>
    
    int main() {
       const std::array< const std::pair<const int, const std::string>, 3 > a {{{1,"2"}, {3,"4"}, {5,"6"}}};   
       std::vector<std::string> r;
       std::transform(std::begin(a), std::end(a), std::back_inserter(r), static_cast<std::string const& (*)(const std::tuple<const int, const std::string>&)>(std::get<1, const int, const std::string>));
       std::copy(std::begin(r), std::end(r), std::ostream_iterator<const std::string>(std::cout, " "));
       return 0;
    }

    У нас новичку на собеседовании предложили продемонстрировать работу (без конкретики) с кортежами и итераторами.
    Что вы можете сказать про его умения, характер и состояние психики? А вы бы этого взяли на работу?
    http://liveworkspace.org/code/2DW59a$0

    LispGovno, 03 Апреля 2013

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

    +20

    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
    int spectrumColor(float magn)
    {
    	if (magn != magn) return 0xFF000000;
    	if ((magn <= -FLT_MAX && magn >= FLT_MAX)) return 0xFF000000;
    	const float minRange = -95.0f;
    	if (magn > minRange && magn <= (minRange + 10.0f))
    		return blendColor(0, 0x00004f, (magn - minRange) / 10.0f);
    	if (magn > (minRange + 10.0f) && magn <= (minRange + 20.0f))
    		return blendColor(0x00004f, 0x50007b, (magn - (minRange + 10.0f)) / 10.0f);
    	if (magn > (minRange + 20.0f) && magn <= (minRange + 30.0f))
    		return blendColor(0x50007b, 0x990076, (magn - (minRange + 20.0f)) / 10.0f);
    	if (magn > (minRange + 30.0f) && magn <= (minRange + 40.0f))
    		return blendColor(0x990076, 0xd20040, (magn - (minRange + 30.0f)) / 10.0f);
    	if (magn > (minRange + 40.0f) && magn <= (minRange + 50.0f))
    		return blendColor(0xd20040, 0xf51f00, (magn - (minRange + 40.0f)) / 10.0f);
    	if (magn > (minRange + 50.0f) && magn <= (minRange + 60.0f))
    		return blendColor(0xf51f00, 0xffaa00, (magn - (minRange + 50.0f)) / 10.0f);
    	if (magn > (minRange + 60.0f) && magn <= (minRange + 70.0f))
    		return blendColor(0xffaa00, 0xfff966, (magn - (minRange + 60.0f)) / 10.0f);
    	if (magn > (minRange + 70.0f) && magn <= (minRange + 80.0f))
    		return blendColor(0xfff966, 0xffffff, (magn - (minRange + 70.0f)) / 10.0f);
    	if (magn < minRange) return 0xFF000000;
    	if (magn >= (minRange + 80.0f)) return 0xFFFFFFFF;
    	return 0xFF000000;
    }

    Вот так в одной говноподелке считается цвет столбцов спектра для визуализации аудио.

    just_nameless, 25 Марта 2013

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

    +20

    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
    #define STR(a) #a
    
    #define EXCEPTION_CLASS_CREATE(a)                   \
    class a : public std::exception                     \
    {                                                   \
    public:                                             \
        a()                                             \
        {                                               \
            d(STR(a)"\n");                              \
        }                                               \
                                                        \
        a(const char * format, ...)                     \
        {                                               \
            char buffer[ 1024 ];                        \
            va_list vl;                                 \
            va_start( vl, format );                     \
            vsnprintf( buffer, sizeof(buffer), format, vl ); \
            va_end( vl );                               \
            _str.append( buffer );                      \
            d(STR(a)" %s\n", buffer);                   \
        }                                               \
                                                        \
        ~a() throw()                                    \
        {                                               \
        }                                               \
                                                        \
        const char* what() const throw()                \
        {                                               \
            return _str.c_str();                        \
        }                                               \
    private:                                            \
        std::string _str;                               \
    };
    // ...
    EXCEPTION_CLASS_CREATE( InternalException )

    Мы очень любим varargs

    roman-kashitsyn, 19 Марта 2013

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

    +20

    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
    94. 94
    95. 95
    #include <iostream>
    #include <functional>
     
    using namespace std;
     
    template<class TReceiver, class TResult>
    struct TMessage
    {
        virtual const TResult sendTo(const TReceiver&) const = 0;
        virtual const TResult sendTo(TReceiver&) const = 0;
        virtual ~TMessage(void){}
    };
     
    template<class TReceiver, class T, class TResult=void>
    struct TTypedMessage : public TMessage<TReceiver, TResult>
    {
            T _data;
            explicit TTypedMessage(const T& data):_data(data)
            {}
     
            const TResult sendTo(const TReceiver& functor) const
            {
                    return functor(_data);
            }
     
            const TResult sendTo(TReceiver& functor) const
            {
                    return functor(_data);
            }
    };
     
    class T1
    {
            typedef T1 TThis;
    public:
            void operator()(const int& i)const{cout <<"int"<< i<<endl;}
            void operator()(const double& i)const{cout <<"double"<< i<<endl;}
            void operator()(const std::reference_wrapper<double>& i)const{cout <<"double&"<< i.get()<<endl;}
            template<class T>
            void operator()(const T& i)const{cout << "UnknowenMesage"<<endl;}
    };
     
    class T2
    {
            typedef T2 TThis;
    public:
            void operator()(int i)const{cout <<"int"<< i<<endl;}
            void operator()(double i)const{cout <<"doble"<< i<<endl;}
            void operator()(std::reference_wrapper<double> i)const{cout <<"double&"<< i.get()<<endl;}
    };
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(TReceiver& Receiver, TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(const TReceiver& Receiver, TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(TReceiver& Receiver, const TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(const TReceiver& Receiver, const TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    int main() {
            T1 a;
            T2 b;
            sendMessage(a, 10);
            sendMessage(a, 10.0);
            double d=0;
            sendMessage(a, std::ref(d));
     
            sendMessage(b, 10);
            sendMessage(b, 10.0);
            sendMessage(b, std::ref(d));
            sendMessage(a, string("kokoko"));
            int aa=6;
            sendMessage(a, aa);
            return 0;
    }

    Найдено на просторах Интранета:
    http://ideone.com/pMSA1p
    В чем смысл? Так получается больше кода?

    LispGovno, 11 Ноября 2012

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

    +20

    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
    void __fastcall TfРѕrm1::SpeedButton1Click(TobjРµct *Sender)
    {
    SpeedButton1->Enabled=false;
     SpeedButton1->Caption=Edit1->Text;
     if(Edit1->Text=="X")
     Edit1->Text="0";
     else
     Edit1->Text="X";
     if(SpeedButton1->Caption=="X" && SpeedButton2->Caption=="X" && SpeedButton3->Caption=="X" ||
     SpeedButton4->Caption=="X" && SpeedButton5->Caption=="X" && SpeedButton6->Caption=="X" ||
     SpeedButton7->Caption=="X" && SpeedButton8->Caption=="X" && SpeedButton9->Caption=="X" ||
     SpeedButton1->Caption=="X" && SpeedButton4->Caption=="X" && SpeedButton7->Caption=="X" ||
      SpeedButton2->Caption=="X" && SpeedButton5->Caption=="X" && SpeedButton8->Caption=="X" ||
       SpeedButton3->Caption=="X" && SpeedButton6->Caption=="X" && SpeedButton9->Caption=="X" ||
        SpeedButton1->Caption=="X" && SpeedButton5->Caption=="X" && SpeedButton9->Caption=="X" ||
         SpeedButton3->Caption=="X" && SpeedButton5->Caption=="X" && SpeedButton7->Caption=="X")
    
      ShowMessage("Ea?a caeii?aia, e?anoeee auea?aee");
    
      else
       if(SpeedButton1->Caption=="0" && SpeedButton2->Caption=="0" && SpeedButton3->Caption=="0" ||
     SpeedButton4->Caption=="0" && SpeedButton5->Caption=="0" && SpeedButton6->Caption=="0" ||
     SpeedButton7->Caption=="0" && SpeedButton8->Caption=="0" && SpeedButton9->Caption=="0" ||
     SpeedButton1->Caption=="0" && SpeedButton4->Caption=="0" && SpeedButton7->Caption=="0" ||
      SpeedButton2->Caption=="0" && SpeedButton5->Caption=="0" && SpeedButton8->Caption=="0" ||
       SpeedButton3->Caption=="0" && SpeedButton6->Caption=="0" && SpeedButton9->Caption=="0" ||
        SpeedButton1->Caption=="0" && SpeedButton5->Caption=="0" && SpeedButton9->Caption=="0" ||
         SpeedButton3->Caption=="0" && SpeedButton5->Caption=="0" && SpeedButton7->Caption=="0")
      ShowMessage("Ea?a caeii?aia, iieeee auea?aee");
    
    }

    jQuery, 29 Октября 2012

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

    +20

    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
    D:\Sources\jimbot_at_cpp>make -f Makefile.win clean-full
    rm -f *.o lib.a dist/jimbot.exe
    
    D:\Sources\jimbot_at_cpp>make -f Makefile.win lib
    gcc -c sqlite3.c -pipe -O2 -g1 DSQLITE_THREADSAFE=1
    gcc.exe: error: DSQLITE_THREADSAFE=1: No such file or directory
    make: *** [lib] Error 1
    
    D:\Sources\jimbot_at_cpp>make -f Makefile.win
    g++ -c *.cpp -std=c++0x -O2 -g1 -pipe -Wno-deprecated -Wno-write-strings -Wno-de
    precated-declarations  -DDEBUG -DEASTER -DTESTER
    g++  -o dist/jimbot -pipe *.o -O2 -g1 lib.a -lpthread -lgnutls -lwsock32 -ladvap
    i32 -lcrypt32 -lsecur32 -ldnsapi -liconv
    g++.exe: error: lib.a: No such file or directory
    make: *** [all] Error 1
    
    D:\Sources\jimbot_at_cpp>

    JavaCoder, 06 Октября 2012

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