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

    +993

    1. 1
    2. 2
    // Randomize
    #define srand(x) srand(x + GetCurrentThreadId())

    Чтобы в разных тредах не выдавало одинаковые последовательности

    k06a, 14 Мая 2010

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class cout_mt : public std::ostringstream
    {
    public:
       ~mt_ostream()
       {
          std::cout << str();
       }
    };
    
    #define cout static_cast<cout_mt&>(cout_mt())

    Для того чтобы не разрывались строки вида: cout << "Value = " << value << ";" << endl; при использовании таких вызовов из нескольких тредов, а то ведь каждый оператор << является вызовом функции и частенько треды мешаю друг другу выводить . . .

    k06a, 14 Мая 2010

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

    +987

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    enum State
    {
       NotOpened  = __LINE__;
       Waiting    = __LINE__;
       Opened     = __LINE__;
       Finished   = __LINE__;
       Terminated = __LINE__;
    };

    k06a, 14 Мая 2010

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

    +1005

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #define KB * 1024
    #define MB KB KB
    #define GB MB KB
    #define TB GB KB
    
    int main( ... )
    {
       char * arr = new char [16 MB];
       ...
    }

    k06a, 14 Мая 2010

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

    +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
    // ...
    // xcrement - (in|de)crement
    // ...
    bool parse( . . . , int xcrement, . . . )
    {
       ...
       while ( ... )
       {
          ...
          index += xcrement;
       }
       ...
    }

    k06a, 14 Мая 2010

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

    +132

    1. 1
    assert(!"Can't change this parameter.");

    k06a, 14 Мая 2010

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

    +971

    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
    #include<stdio.h>
    #include<stdlib.h>
    #define N 3
    using namespace std;
    /*class Node{
    struct Node *f,*s,*t;
    public :
    int x,y;
    
    void Node(int rx,int ry){
    x=rx;
    y=ry;
    return;
    }
    
    };*/
    
    typedef struct node{int x,y}node;
    node tree[100];
    node jmps[3];
    
    
    int main(){
    // Node *root=new Node(-1,-1);
    int i=0,j;
    ////////////////////////
    
    
    ////////////////////////
    tree[0].x=-1;
    tree[0].y=-1;
    
     for(i=0;i<N;i++){
    	for(j<N*)
     
     }
    
    }

    KOLANICH, 14 Мая 2010

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

    +974

    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
    /*Вариант - вручную*/
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    int main(int argc, char* argv[]) {
      std::map<std::string, std::pair<int, int> > files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      std::map<std::string, std::pair<int, int> >::const_iterator begin = files.begin();
      std::map<std::string, std::pair<int, int> >::const_iterator end = files.end();
      int num = 21;
      for (; begin != end; ++begin) {
        if (num >= (*begin).second.first && num <= (*begin).second.second) {
          std::cout << "Found in " + (*begin).first + "\n";
          break;
        }
      }
      return 0;
    }
    
    /*Вариант - STL+BOOST*/
    #include <algorithm>
    #include <functional>
    #include <iostream>
    #include <map>
    #include <string>
    #include <utility>
    
    #include <boost/bind.hpp>
    
    int main(int argc, char* argv[]) {
      typedef std::map<std::string, std::pair<int, int> > map_type;
      map_type files;
      files["0.txt"] = std::make_pair(0, 7);
      files["1.txt"] = std::make_pair(8, 41);
      files["2.txt"] = std::make_pair(42, 50);
      int num = 21;
      map_type::const_iterator elem;
      elem = std::find_if(
                          files.begin(),
                          files.end(),
                          boost::bind(
                                      std::logical_and<bool>(),
                                      boost::bind(
                                                  std::less_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::first,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num),
                                      boost::bind(
                                                  std::greater_equal<int>(),
                                                  boost::bind(
                                                              &map_type::value_type::second_type::second,
                                                              boost::bind(
                                                                          &map_type::value_type::second,
                                                                          _1)
                                                              ),
                                                  num)));
      if (elem != files.end())
        std::cout << "Found in " + (*elem).first + "\n";
      return 0;
    }

    Смысл в том, чтобы с данным значением(пример 21) пройтись по таблице и найти в каком элементе данное число(21) находится в диапазоне std::pair<int, int>...
    Сначала написал вручную, но т.к. нужно было сделать с помощью STL, получилось сие чудо.

    rudvil, 13 Мая 2010

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

    +960

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // Encode() takes in reference to data. We now pass in reference to data instead of the
    // entire data object to Encode() as it was causing memory leak(with the data object copy
    // not getting deleted.
    
      Data &tempData = *data;
      Data::Encode(tempData, &encodedRequest, requestSize, 0);

    Перевод:
    Encode() принимает ссылку на data. Давайте передадим туда ссылку,
    а то раньше мы передавали объект целиком, и это приводило к утечкам памяти (копия объекта не удалялась).


    Здесь впору процитировать "Бойцовский Клуб":
    -А в какой Вы фирме работаете?
    -В крупной...

    belca, 13 Мая 2010

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

    +144

    1. 1
    2. 2
    3. 3
    /*
    Некий не работающий кусок закомментированного кода.
    *///It's fuckin shit C++!!!

    Обнаружено в одном из наших проектов.

    Говногость, 13 Мая 2010

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