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

    В номинации:
    За время:
  2. C++ / Говнокод #17616

    +55

    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
    uint8_t const Q_ROM QF_div8Lkup[65] = {
        static_cast<uint8_t>(0), // unused location
        static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(0), static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(0), static_cast<uint8_t>(0),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(1), static_cast<uint8_t>(1),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(2), static_cast<uint8_t>(2),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(3), static_cast<uint8_t>(3),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(4), static_cast<uint8_t>(4),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(5), static_cast<uint8_t>(5),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(6), static_cast<uint8_t>(6),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7), static_cast<uint8_t>(7),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7), static_cast<uint8_t>(7),
        static_cast<uint8_t>(7), static_cast<uint8_t>(7)
    };
    
    // ....
    
        //! the function evaluates to TRUE if the priority set has the element n.
        bool hasElement(uint_fast8_t const n) const {
            uint_fast8_t const m =
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_div8Lkup[n]));
            return ((m_bits[m]
                      & static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[n])))
                   != static_cast<uint_fast8_t>(0));
        }
    
        //! insert element \a n into the set, n = 1..64
        void insert(uint_fast8_t const n) {
            uint_fast8_t m =
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_div8Lkup[n]));
            m_bits[m] |= static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[n]));
            m_bytes   |=
                static_cast<uint_fast8_t>(Q_ROM_BYTE(QF_pwr2Lkup[m
                                              + static_cast<uint_fast8_t>(1)]));
        }

    делим на 8 в индустриальном С++. это такой специальный вариант крестов где пользователям сначала лоботомию делают.

    из реализации bitset'а. insert() приведен в качестве примера.

    Dummy00001, 11 Февраля 2015

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

    +55

    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
    else if(block->o_type == O_else)
        {
          block->o_type = O_else;
        }
      else if(block->o_type == O_endif)
        {
          block->o_type = O_endif;
        }
      else if(block->o_type == O_break)
        {
          block->o_type = O_break;
        }
      else if(block->o_type == O_continue)
        {
          block->o_type = O_continue;
        }
      else if(block->o_type == O_endwhile)
        {
          block->o_type = O_endwhile;
        }

    Lavir_the_Whiolet, 11 Января 2015

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

    +55

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    QString GetVer(QString FileName)
    {
        //многакода
        FileName.clear(); //теперь это версия %)
        QTextStream(&FileName) << HIWORD(fi->dwFileVersionMS) << "." << LOWORD(fi->dwFileVersionMS) << "." << HIWORD(fi->dwFileVersionLS) << "." << LOWORD(fi->dwFileVersionLS);
        return FileName;
    }

    кому-то лень было создавать переменную

    kin63camapa, 27 Ноября 2014

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

    +55

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    QByteArray ba;
    char x;
    
    x = 0x05;
    ba.append (&x, sizeof (x));

    Qt. Продолжаем мучить QByteArray :)

    ealx, 26 Ноября 2014

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

    +55

    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
    On Wed, 29 Oct 2014 20:29:33 +0000
    via Digitalmars-d <[email protected]> wrote:
    
    > On Wednesday, 29 October 2014 at 20:13:34 UTC, ketmar via 
    > Digitalmars-d wrote:
    > > On Wed, 29 Oct 2014 13:07:38 -0700
    > > Walter Bright via Digitalmars-d <[email protected]> 
    > > wrote:
    > >
    > >> There are still two string types, something you can't quite 
    > >> escape dealing with.
    > > and D has three string types. it's even better than C++!
    > 
    > Only three? C++ has seven:
    > 
    > 1. const char*  /* zero terminated single byte*/
    > 2. const char*  /* zero terminated multi byte */
    > 3. const wchar_t*  /* zero terminated wide */
    > 4. std::string	
    > 5. std::wstring
    > 6. std::u16string
    > 7. std::u32string
    ah, D has those 'char*' family too, but i don't count them as string
    types. ok, C++ wins. again. ;-)

    Хоть и не код, но смешно.
    Источник: http://forum.dlang.org/thread/[email protected]?page=3

    rst256, 18 Ноября 2014

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

    +55

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void input (char inpt [64])
    {
    	for (;;)
    	{
    		int i(0);
    		cin >> inpt;
    		i ++;
    		if (inpt[i] == '\n')
    			inpt[i] = '\0';break;
    	}
    }

    normbo, 03 Ноября 2014

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

    +55

    1. 1
    2. 2
    // Извиняюсь, но кода не будет, только ссылка.
    // https://github.com/fruxo/turbobadger

    >> With compilers supporting C+ + 11
    Вот лично против либы ничего не имею - годная получилась. Но..
    Аффтар заучил nullptr, и считает что теперь он использует c++11.
    Епт, да эта либа спокойно собирается под vc2008, стоит только задефайнить nullptr как 0.

    Pythoner, 16 Октября 2014

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

    +55

    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
    bool nt_utils::enum_processes(std::vector<uint32_t>& pids)
    {
      pids.clear();
    
      PDWORD process_ids = NULL;
      DWORD cb = ALLOC_SIZE;
      DWORD bytes_returned = 0;
      BOOL complete = FALSE;
    
      __try {
    
        while (!complete) {
          process_ids = static_cast<PDWORD>(
            ::HeapAlloc(
              ::GetProcessHeap(),
              HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
              cb
            )
          );
    
          if (::EnumProcesses(process_ids, cb, &bytes_returned)) {
            if (cb == bytes_returned) {
              ::HeapFree(::GetProcessHeap(), 0, process_ids);
              process_ids = NULL;
              cb *= 2;
            } else {
              complete = TRUE;
            }
          } else {
            ::HeapFree(::GetProcessHeap(), 0, process_ids);
            process_ids = NULL;
            complete = TRUE;
          }
        }
        
        if (process_ids) {
          DWORD size = bytes_returned / sizeof(DWORD);
          pids.reserve(size);
          for (DWORD i = 0; i < size; ++i) {
            assert(process_ids[i]);
            pids[i] = process_ids[i];
          }
          ::HeapFree(::GetProcessHeap(), 0, process_ids);
        }
    
      } __except (EXCEPTION_EXECUTE_HANDLER) {
        if (process_ids) {
          ::HeapFree(::GetProcessHeap(), 0, process_ids);
        }
        return false;
      }
    
      return !!process_ids;
    }

    Получение id всех процессов

    gc4242, 14 Октября 2014

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

    +55

    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
    //--------------------------------------------------------------------------
    
    	#define DEF_P(X, Y, N) X##N
    	#define DEF_D(X, Y, N) X##N Y##N
    	#define DP1(DT, X, Y) DT(X, Y, 0)
    
    	//--------------------------------------------------------------------------
    
    	#define DP2(DT, X, Y) DP1(DT, X, Y), DT(X, Y, 1)
    	#define DP3(DT, X, Y) DP2(DT, X, Y), DT(X, Y, 2)
    	#define DP4(DT, X, Y) DP3(DT, X, Y), DT(X, Y, 3)
    	#define DP5(DT, X, Y) DP4(DT, X, Y), DT(X, Y, 4)
    	#define DP6(DT, X, Y) DP5(DT, X, Y), DT(X, Y, 5)
    	#define DP7(DT, X, Y) DP6(DT, X, Y), DT(X, Y, 6)
    	#define DP8(DT, X, Y) DP7(DT, X, Y), DT(X, Y, 7)
    	#define DP9(DT, X, Y) DP8(DT, X, Y), DT(X, Y, 8)
    	#define DP10(DT, X, Y) DP9(DT, X, Y), DT(X, Y, 9)
    	#define DP11(DT, X, Y) DP10(DT, X, Y), DT(X, Y, 10)
    	#define DP12(DT, X, Y) DP11(DT, X, Y), DT(X, Y, 11)
    	#define DP13(DT, X, Y) DP12(DT, X, Y), DT(X, Y, 12)
    	#define DP14(DT, X, Y) DP13(DT, X, Y), DT(X, Y, 13)
    	#define DP15(DT, X, Y) DP14(DT, X, Y), DT(X, Y, 14)
    
    	//--------------------------------------------------------------------------
    	// define functor for params count 0
    	//--------------------------------------------------------------------------
    
    	#define TEMP_DEF_PARAM(N)
    	#define TEMP_SPC_PARAM(N)
    	#define FUNC_PTR_PARAM(N)
    	#define FUNC_INV_PARAM(N)
    	#define FUNC_DEF_PARAM(N)
    	DEFINE_FUNCTOR(0);
    
    	#undef TEMP_DEF_PARAM
    	#undef TEMP_SPC_PARAM
    	#undef FUNC_PTR_PARAM
    	#undef FUNC_INV_PARAM
    	#undef FUNC_DEF_PARAM
    
    	//--------------------------------------------------------------------------
    	// define functor for other params counts
    	//--------------------------------------------------------------------------
    
    	#define TEMP_DEF_PARAM(N) 	,DP##N(DEF_P, typename T,)
    	#define TEMP_SPC_PARAM(N)	,DP##N(DEF_P, T,)
    	#define FUNC_PTR_PARAM(N)	DP##N(DEF_P, T,)
    	#define FUNC_INV_PARAM(N)	DP##N(DEF_P, p,)
    	#define FUNC_DEF_PARAM(N)	DP##N(DEF_D, T, p)
    
    	DEFINE_FUNCTOR(1);
    	DEFINE_FUNCTOR(2);
    	DEFINE_FUNCTOR(3);
    	DEFINE_FUNCTOR(4);
    	DEFINE_FUNCTOR(5);
    	DEFINE_FUNCTOR(6);
    	DEFINE_FUNCTOR(7);
    	DEFINE_FUNCTOR(8);
    	DEFINE_FUNCTOR(9);
    	DEFINE_FUNCTOR(10);
    	DEFINE_FUNCTOR(11);
    	DEFINE_FUNCTOR(12);
    	DEFINE_FUNCTOR(13);
    	DEFINE_FUNCTOR(14);
    	DEFINE_FUNCTOR(15);

    Весь пиздец https://github.com/Evil-Spirit/Nutmeg/blob/master/CoreSrc/Common/Functor.h
    Дети, не программируйте на C++

    FadeToBlack, 15 Августа 2014

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

    +55

    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
    #include <iostream>
    #include <thread>
    #include <cmath>
    #include <cstdlib>
    #include <algorithm>
    #include <iterator>
    #include <future>
    
    constexpr std::size_t array_size = 1e7;
    constexpr std::size_t chunks_number = 1e3;
    
    double local_pi(const std::size_t array_length)
    {
        std::vector<std::pair<double, double>> array_xy;       
        array_xy.reserve(array_length);      
        std::generate_n(std::back_inserter(array_xy), array_length, [](){
          return std::make_pair(rand()/static_cast<double>(RAND_MAX), 
    			    rand()/static_cast<double>(RAND_MAX));
          });
        std::vector<bool> bool_z;
        bool_z.reserve(array_length);
        auto bool_z_insterter = std::back_inserter(bool_z);
        std::for_each(array_xy.cbegin(), array_xy.cend(), [&](const std::pair<double, double>& ref){
          const auto func = [](const std::pair<double, double>& ref){
    	return sqrt(pow(ref.first, 2) + pow(ref.second, 2)) <= 1.0;
          };
          bool_z_insterter = func(ref);
        });
        const auto sum = 4.0 * (std::accumulate(bool_z.cbegin(), bool_z.cend(), 0.0)/array_length);
        return sum;
    }
    int main(){
      const auto concurrency_level = std::thread::hardware_concurrency();
      std::vector< double > chunks_vector;
      chunks_vector.reserve(chunks_number);
      for (std::size_t j = 0; j < chunks_number; ++j) {
        std::vector<std::future<double>> futures;
        futures.reserve(concurrency_level-1);
        for (std::size_t i = 0; i < concurrency_level-1; ++i){
          auto f = std::async(std::launch::async, local_pi, array_size/concurrency_level);
          futures.push_back(std::move(f));
        }
        auto pi = local_pi(array_size/concurrency_level);
        for (auto&& x : futures ){
          pi += x.get();
        }
        pi /= concurrency_level;
        chunks_vector.push_back(pi);
      }
      const auto total_pi = std::accumulate(chunks_vector.cbegin(), chunks_vector.cend(), 0.0)/chunks_vector.size();
      std::cout << "Pi equals = " << std::scientific << total_pi << std::endl;
      return 0;
    }

    Вычисляем pi методом Монте-Карло

    Abbath, 10 Февраля 2014

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