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

    +1

    1. 1
    TBufferedFileInput storage(sprintf("%s", path));

    Весьма оригинальный способ приведения типа к самому себе.

    skyhawk, 30 Сентября 2015

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

    −4

    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 <stdio.h>
    #include <iostream>
    #include <regex>
    using namespace std;
    int cube(int);
    int main()
    {
            char number;
            label:
            cout << " Введите число " << endl;
            cin >> number;
            regex txt_regex("/^\d+$/");
        if (!regex_match(number, txt_regex))
        {
            cout << "Вводить можно только цифры!" << endl;
            goto label;
        }
        int value = atoi(number);
            int result = cube(value);
            cout << "Куб числа " << number << " равен " << result;
        return 0;
    }
    int cube(int number)
    {
          return number * number * number; 
    }

    Возведение числа в куб.

    Exclumice, 30 Сентября 2015

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

    +3

    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
    #ifndef DEFINES
    #define DEFINES
    
    #define _W_CALL(a,b) a b
    
    #define _W_NARGS_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N, ...) N
    #define _W_NARGS(...) _W_NARGS_OVERRIDE("ignored", ##__VA_ARGS__, 10, 9, 8, 7, 6 ,5, 4, 3, 2, 1, 0)
    
    
    #define _W_GETPARAM1(_1,...) _1
    #define _W_GETPARAM2(_1,_2,...) _2
    #define _W_GETPARAM3(_1,_2,_3,...) _3
    
    
    #define _W_ARG_OVERRIDE(_1, _2, _3, NAME, ...) NAME
    #define _W_ARG2(a,b) (a,b)
    #define _W_ARG3(a,b,c) (a,b,c)
    #define W_ARG(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARG3, _W_ARG2)(__VA_ARGS__)
    
    
    #define _W_ARGNAME2(a,b) b
    #define _W_ARGNAME3(a,b,c) b
    #define _W_ARGNAME_(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARGNAME3, _W_ARGNAME2)(__VA_ARGS__)
    #define _W_ARGNAME(a) _W_ARGNAME_ a
    
    #define _W_ARGPREP2(a,b) a b
    #define _W_ARGPREP3(a,b,c) a bc
    #define _W_ARGPREP_(...) _W_ARG_OVERRIDE(__VA_ARGS__, _W_ARGPREP3, _W_ARGPREP2)(__VA_ARGS__)
    #define _W_ARGPREP(a) _W_ARGPREP_ a
    
    #define _W_FUNCTPARAM1(a) _W_ARGPREP(a)
    #define _W_FUNCTPARAM2(a,b) _W_ARGPREP(a), _W_ARGPREP(b)
    #define _W_FUNCTPARAM3(a,b,c) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c)
    #define _W_FUNCTPARAM4(a,b,c,d) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d)
    #define _W_FUNCTPARAM5(a,b,c,d,e) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e)
    #define _W_FUNCTPARAM6(a,b,c,d,e,f) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f)
    #define _W_FUNCTPARAM7(a,b,c,d,e,f,g) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g)
    #define _W_FUNCTPARAM8(a,b,c,d,e,f,g,h) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h)
    #define _W_FUNCTPARAM9(a,b,c,d,e,f,g,h,i) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h), _W_ARGPREP(i)
    #define _W_FUNCTPARAM10(a,b,c,d,e,f,g,h,i,j) _W_ARGPREP(a) , _W_ARGPREP(b) , _W_ARGPREP(c) , _W_ARGPREP(d) , _W_ARGPREP(e) , _W_ARGPREP(f), _W_ARGPREP(g), _W_ARGPREP(h), _W_ARGPREP(i), _W_ARGPREP(j)
    
    #define _W_FUNCTPARAMS_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
    #define _W_FUNCTPARAMS(...) _W_FUNCTPARAMS_OVERRIDE(__VA_ARGS__,_W_FUNCTPARAM10,_W_FUNCTPARAM9,_W_FUNCTPARAM8,_W_FUNCTPARAM7,_W_FUNCTPARAM6,_W_FUNCTPARAM5,_W_FUNCTPARAM4,_W_FUNCTPARAM3,_W_FUNCTPARAM2,_W_FUNCTPARAM1)(__VA_ARGS__)
    
    
    #define _W_FUNCTNAME1(a) _W_ARGNAME(a)
    #define _W_FUNCTNAME2(a,b) _W_ARGNAME(a), _W_ARGNAME(b)
    #define _W_FUNCTNAME3(a,b,c) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c)
    #define _W_FUNCTNAME4(a,b,c,d) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d)
    #define _W_FUNCTNAME5(a,b,c,d,e) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e)
    #define _W_FUNCTNAME6(a,b,c,d,e,f) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f)
    #define _W_FUNCTNAME7(a,b,c,d,e,f,g) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g)
    #define _W_FUNCTNAME8(a,b,c,d,e,f,g,h) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h)
    #define _W_FUNCTNAME9(a,b,c,d,e,f,g,h,i) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h), _W_ARGNAME(i)
    #define _W_FUNCTNAME10(a,b,c,d,e,f,g,h,i,j) _W_ARGNAME(a) , _W_ARGNAME(b) , _W_ARGNAME(c) , _W_ARGNAME(d) , _W_ARGNAME(e) , _W_ARGNAME(f), _W_ARGNAME(g), _W_ARGNAME(h), _W_ARGNAME(i), _W_ARGNAME(j)
    
    
    #define _W_FUNCTNAMES_OVERRIDE(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
    #define _W_FUNCTNAMES(...) _W_FUNCTNAMES_OVERRIDE(__VA_ARGS__,_W_FUNCTNAME10,_W_FUNCTNAME9,_W_FUNCTNAME8,_W_FUNCTNAME7,_W_FUNCTNAME6,_W_FUNCTNAME5,_W_FUNCTNAME4,_W_FUNCTNAME3,_W_FUNCTNAME2,_W_FUNCTNAME1)(__VA_ARGS__)
    
    
    #define W_FUNCT(className, retType, functName, ...) \
        private: \
            retType _##functName(  _W_FUNCTPARAMS(__VA_ARGS__) ); \
            retType (className::*__##functName)( _W_FUNCTPARAMS(__VA_ARGS__)  ); \
        public: \
            retType functName( _W_FUNCTPARAMS(__VA_ARGS__) ) { return (this->*__##functName)( _W_FUNCTNAMES(__VA_ARGS__) );  }
    
    
    #define W_FUNCT_REL(className, functName, classPointer) classPointer->__##functName = & className::_##functName;
    
    
    #define _W_STRING(X) #X
    
    
    
    #endif // DEFINES

    Немножко надэфайнил.

    PavelK, 29 Сентября 2015

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

    +1

    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
    import std.io;
    import std.string;
    import calendar.month;
    
    module calendar.date;
    
    namespace Chrono
    {
        export
        struct Date {
            Date(int, Month, int);
            int day() const
            {
                return d;
            }
            Month month() const
            {
                return m;
            }
            Int year() const
            {
                return y;
            }
        private:
            int d;
            Month m;
            int y;
        };
        export
        std::ostream &operator<<(std::ostream &, const Date &);
        export
        std::string to_string(const Date &);
    }

    По мотивам: http://habrahabr.ru/company/infopulse/blog/267781/
    зы. https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Large-Scale-C%2B%2B-With-Modules.pdf

    CriDos, 27 Сентября 2015

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

    +4

    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
    long long int Factorial(long long int m_nValue)
       {
           long long int result=m_nValue;
           long long int result_next;
           long long int pc = m_nValue;
           do
           {
               result_next = result*(pc-1);
               result = result_next;
               pc--;
           }while(pc>2);
           m_nValue = result;
           return m_nValue;
       }

    http://rosettacode.org/wiki/Factorial#C.2B.2B

    Abbath, 22 Сентября 2015

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

    +2

    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
    #include <memory>
    #include <list>
    
    struct ListNode;
    using List = std::unique_ptr<const ListNode>;
    
    struct ListNode {
        const int data;
        const List next;
        
        ~ListNode()
        {
            if(!next)
    	    return;
    	else {
    	    std::list<ListNode*> nodes;
    	    for(auto pn = next.get(); pn->next; pn = pn->next.get()) {
    		nodes.push_back(const_cast<ListNode*>(pn));
    	    }
    	    for(decltype(nodes)::reverse_iterator in = nodes.rbegin(); in != nodes.rend(); ++in) {
    		const_cast<List&>((*in)->next).reset();
    	    }
    	}
        }
    };
    
    List Cons(int head, List tail)
    {
        return List(new ListNode{head, std::move(tail)});
    }
    
    List Nil()
    {
        return List();
    }
    
    size_t len(const List & self)
    {
        if (!self) {
            return 0;
        }
        return 1 + len(self->next);
    }
    
    #include <iostream>
    
    void test(size_t n)
    {
        auto p = Nil();
        for (size_t i = 0; i < n; ++i) {
            auto x = std::move(p);
            p = Cons(1, std::move(x));
        }
        std::cout << "done: " << std::endl;
    }
    
    int main()
    {
        test(131028);
    }

    односвязный список против джависта
    источник: https://www.linux.org.ru/forum/development/11752940?cid=11755489

    CHayT, 22 Сентября 2015

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

    +1

    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
    class DBUSLIB_EXPORT DBusLib : public QObject
    {
        Q_OBJECT
    public:
        DBusLib(QObject* parent = 0);
        void requestId(const QString &req, const int &reqTimeOut);
    
        QByteArray replyData;
        QString name;
        MyPair reqStruct;  // id, partsCount
        QVector<QByteArray> vecFile;
        int partsCount; //кол-во частей
        int parts; //кол-во пришедших
        QTimer *timer = new QTimer(this);
    
    signals:
        void doneSignal(QByteArray& fileData);
    
    public slots:
        void requestMap(const MyPair &dbm);
        void partsFile(const MyPair &part);
        void requestFail(const QDBusError& error);
        void timeIsOver();
    
    };

    Студент принес говна. Паблик морозов, ценные комментарии и все такое.
    Вот только мне любопытна 14 строчка. C++11 не включен.
    Конпелятор mingw492 выбрасывает ворнинг
    D:\projects\test_dbus\client_v2\client_l ib\dbuslib.h:35: предупреждение: non-static data member initializers only available with -std=c++11 or -std=gnu++11
    QTimer *timer = new QTimer(this);
    ^
    Но при этом все компилится и работает. Значит, 03 стандарт разрешает такое?

    scp, 17 Сентября 2015

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

    +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
    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
    #include <bits/stdc++.h>
    #define MP make_pair
    #define PB push_back
    #define int long long
    #define st first
    #define nd second
    #define rd third
    #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
    #define RE(i, n) FOR(i, 1, n)
    #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
    #define REP(i, n) for(int i = 0;i <(n); ++i)
    #define VAR(v, i) __typeof(i) v=(i)
    #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
    #define ALL(x) (x).begin(), (x).end()
    #define SZ(x) ((int)(x).size())
    #ifdef LOCAL
    #define debug(x) {cerr <<#x<<" = " <<x<<"\n"; }
    #define debug2(x, y) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
    #define debug3(x, y, z) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
    #define debug4(x, y, z, t) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#t <<" = " <<t<<"\n";}
    #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
    #else
    #define debug(x)
    #define debug2(x, y)
    #define debug3(x, y, z)
    #define debug4(x,y,z,t)
    #define debugv(x)
    #define cerr if(0)cout
    #endif
    #define make(type, x) type x; cin>>x;
    #define make2(type, x, y) type x, y; cin>>x>>y;
    #define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
    #define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
    #define next ____next
    #define prev ____prev
    #define left ____left
    #define hash ____hash
    using namespace std;
    typedef long long ll;
    typedef long double LD;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    typedef vector<ll> VLL;
    typedef vector<pair<int, int> > VPII;
    typedef vector<pair<ll, ll> > VPLL;

    Даже #define int long long есть
    http://codeforces.com/contest/575/submission/12867420

    3_dar, 15 Сентября 2015

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

    −1

    1. 1
    #define y1 asdfgfgdvf

    Нехрена юзать глобальные переменные.

    3_dar, 15 Сентября 2015

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

    +1

    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
    void RedoLayout(HWND dialogWindow)
    {
    	RECT rectangle;
    	GetClientRect(dialogWindow, &rectangle);
    
    	/* Status */
    	SetWindowPos(GetDlgItem(dialogWindow, IDC_STATUS), dialogWindow, 
    		0,
    		rectangle.bottom - (layout[2].bottom - layout[2].top),
    		rectangle.right - rectangle.left,
    		(layout[2].bottom - layout[2].top),
    		SWP_NOZORDER);
    
    	/* Panel */
    	SetWindowPos(
    		GetDlgItem(dialogWindow,IDC_PANEL), dialogWindow,
    		(layout[1].left - layout[0].left),
    		(layout[1].top - layout[0].top),
    		rectangle.right - (layout[1].left-layout[0].left) - (layout[0].right - layout[1].right),
    		rectangle.bottom - (layout[1].top - layout[0].top) - (layout[0].bottom - layout[1].bottom),
    		SWP_NOZORDER);
    
    	/* Buttons & CheckBoxes */
    	for (int i = 0; i < sizeof(controls) / sizeof(controls[0]); ++i)
    	{
    		SetWindowPos(
    			GetDlgItem(dialogWindow,controls[i]), dialogWindow,
    			rectangle.right - (layout[0].right - layout[3 + i].left),
    			(layout[3 + i].top - layout[0].top),
    			(layout[3 + i].right - layout[3 + i].left),
    			(layout[3 + i].bottom - layout[3 + i].top),
    			SWP_NOZORDER);
    	}
    }

    Из SDK к Intel RealSense

    kingmonstr, 13 Сентября 2015

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