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

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    auto&& rv = elements | std::ranges::views::values | std::ranges::views::transform([](auto&& a) -> auto 
    		{
    			StatisticsElementMultiple n = std::move(a);
    			n.nanosec /= n.count;
    			return n;
    		});
    		std::vector<StatisticsElementMultiple> el(std::begin(rv), std::end(rv));
    		std::ranges::sort(el, [](auto&& a, auto&& b) -> bool {return a.nanosec > b.nanosec; });
    		for(auto&& [nanosec, name, prefixes, count] : el)
    		{
    			printf("%-10d %04X %12s %6d\n", count, prefixes, name.c_str(), nanosec);
    		}

    kcalbCube, 18 Апреля 2022

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

    0

    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
    // https://github.com/gcc-mirror/gcc/blob/ec03862f809e544a9b7d28067e51597dc92a0244/libstdc%2B%2B-v3/include/bits/forward_list.tcc#L391-L411
    
      template<typename _Tp, typename _Alloc>
        bool
        operator==(const forward_list<_Tp, _Alloc>& __lx,
    	       const forward_list<_Tp, _Alloc>& __ly)
        {
          //  We don't have size() so we need to walk through both lists
          //  making sure both iterators are valid.
          auto __ix = __lx.cbegin();
          auto __iy = __ly.cbegin();
          while (__ix != __lx.cend() && __iy != __ly.cend())
    	{
    	  if (!(*__ix == *__iy))
    	    return false;
    	  ++__ix;
    	  ++__iy;
    	}
          if (__ix == __lx.cend() && __iy == __ly.cend())
    	return true;
          else
    	return false;
        }

    из стандартной библиотеки крестоговна от GCC

    j123123, 13 Апреля 2022

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

    0

    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
    // https://github.com/santiontanon/stransball2/blob/dff413c6ed236b4be23e0152557a26d7d902976c/sources/state_changepack.cpp#L67
    
    bool state_changepack_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard)
    {
    	if (SUBSTATE==0) {
    		if (image!=0) SDL_FreeSurface(image);
    		image=IMG_Load("graphics/tittle.pcx");
    
    		{
    			levelpacks.Delete();
                                                             
    #ifdef _WIN32
                            /* Find files: */ 
                            WIN32_FIND_DATA finfo;
                            HANDLE h;
    
                            h=FindFirstFile("maps/*.lp",&finfo);
                            if (h!=INVALID_HANDLE_VALUE) {
                                    char *tmp;
    
                                    tmp=new char[strlen(finfo.cFileName)+1];
                                    strcpy(tmp,finfo.cFileName);
                                    levelpacks.Add(tmp);
    
                                    while(FindNextFile(h,&finfo)==TRUE) {
                                        char *tmp;
    
                                        tmp=new char[strlen(finfo.cFileName)+1];
                                        strcpy(tmp,finfo.cFileName);
                                        levelpacks.Add(tmp);
                                    } /* while */ 
                            } /* if */ 
    #else
                            DIR *dp;
                            struct dirent *ep;
    		  
                            dp = opendir ("maps");
                            if (dp != NULL)
                            {
                                while (ep = readdir (dp))
                                {
                                    char *tmp;
                             
                                    if (strlen(ep->d_name)>4 &&
                                        ep->d_name[strlen(ep->d_name)-3]=='.' &&
                                        ep->d_name[strlen(ep->d_name)-2]=='l' &&
                                        ep->d_name[strlen(ep->d_name)-1]=='p') {
                                        tmp=new char[strlen(ep->d_name)+1];
                                        strcpy(tmp,ep->d_name);
                                        levelpacks.Add(tmp);                                    
                                    } /* if */
                                   
                                }
                                (void) closedir (dp);
                            }
    #endif

    Super Transball 2 (супер трансшары 2)

    j123123, 04 Апреля 2022

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

    0

    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
    void SoftSPIB::setClockDivider(uint8_t div) {
        if (div == SPI_CLOCK_DIV2) _delay = 2;
        else if (div == SPI_CLOCK_DIV4) _delay = 4;
        else if (div == SPI_CLOCK_DIV8) _delay = 8;
        else if (div == SPI_CLOCK_DIV16) _delay = 16;
        else if (div == SPI_CLOCK_DIV32) _delay = 32;
        else if (div == SPI_CLOCK_DIV64) _delay = 64;
        else if (div == SPI_CLOCK_DIV128) _delay = 128;
        else _delay = 128;
    }
    
    uint8_t SoftSPIB::transfer(uint8_t val) {
        ...
        uint8_t del = _delay >> 1;
    
        uint8_t bval = 0;
        for (uint8_t bit = 0; bit < 8; bit++) {
            digitalWrite(_sck, _ckp ? LOW : HIGH);
    
            for (uint8_t i = 0; i < del; i++) {
                    asm volatile("nop");
            }
    
            if (...) {...} else {
                    digitalWrite(_mosi, val & (1<<bit) ? HIGH : LOW);
            }
        ...
        ...
        ...
        }
        return out;
    }

    - А это точно частота CLOCK_DIV2? /* Fosc/2 */
    - Не боись, я все рассчитал!

    Steve_Brown, 17 Марта 2022

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

    0

    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
    int main() {
    
      ifstream input_file;
    
      input_file.open("DATA");
      
      string line;
      while (getline(input_file, line)) {
        size_t i = 0, j = 0;
        string fname, sname;
        float score;
    
        char c = line[0];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        fname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        c = line[i];
        while((c != ' ') && (j < line.size())) {
          c = line[j];
          j++;
        }
        sname = line.substr(i, j - i - 1);
        i = j;
        j += 1;
    
        score = stof(line.substr(i, line.size()));
    
        Data dat;
        dat.fname = fname;
        dat.sname = sname;
        dat.score = score;
    
        vec.push_back(dat);
      }
      
      const auto comp_fname = [](Data a, Data b){return a.fname >= b.fname;};
      const auto comp_sname = [](Data a, Data b){return a.sname >= b.sname;};
      const auto comp_score = [](Data a, Data b){return a.score >= b.score;};
    
      const auto dcomp_fname = [](Data a, Data b){return a.fname < b.fname;};
      const auto dcomp_sname = [](Data a, Data b){return a.sname < b.sname;};
      const auto dcomp_score = [](Data a, Data b){return a.score < b.score;};
    
      print(vec);
      char choice = 0, order = 0;
      cout << "Как сортировать (0 - Fфмилия, 1 - Iмя, 2 - CpegHuu_6aJlJl): ";
      cin >> choice;
      cout << "А в какмо порядке?7? (0 - по убыванию, 1 - по возрастанию)Ж ";
      cin >> order;
      
      if (choice == '0') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_fname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_fname);
        }
      } else if (choice == '1') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_sname);
        } else {
          sort(vec.begin(), vec.end(), dcomp_sname);
        }
      } else if (choice == '2') {
        if (order == '0') {
          sort(vec.begin(), vec.end(), comp_score);
        } else {
          sort(vec.begin(), vec.end(), dcomp_score);
        }
      }
    
    // и т.д. ...

    Как вам? Зачёт? Незачёт? Удовлетворительно?

    JloJle4Ka, 12 Марта 2022

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

    0

    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
    #define CONSTRUCT_JUMP(name_, opcode_) else if(mnemonic.name == #name_) \
    	subcompileMnemonic(mnemonic, {\
    	{constructDescription(CONSTANT), opcode_},\
    	{constructDescription(LABEL), opcode_}})
    
    	CONSTRUCT_JUMP(JMP, JMP);
    
    	CONSTRUCT_JUMP(JE, JZ);
    	CONSTRUCT_JUMP(JZ, JZ);
    
    	CONSTRUCT_JUMP(JNZ, JNZ);
    	CONSTRUCT_JUMP(JNE, JNZ);
    
    	CONSTRUCT_JUMP(JG, JG);
    	CONSTRUCT_JUMP(JNLE, JG);
    	CONSTRUCT_JUMP(JNLZ, JG);
    
    	CONSTRUCT_JUMP(JLE, JNG);
    	CONSTRUCT_JUMP(JLZ, JNG);
    	CONSTRUCT_JUMP(JNG, JNG);
    
    	CONSTRUCT_JUMP(JGE, JGZ);
    	CONSTRUCT_JUMP(JGZ, JGZ);
    	CONSTRUCT_JUMP(JNL, JGZ);
    
    	CONSTRUCT_JUMP(JNGZ, JL);
    	CONSTRUCT_JUMP(JNGE, JL);
    	CONSTRUCT_JUMP(JL  , JL);
    
    	CONSTRUCT_JUMP(JB, JB);
    	CONSTRUCT_JUMP(JNAE, JB);
    	CONSTRUCT_JUMP(JNAZ, JB);
    	CONSTRUCT_JUMP(JC, JB);
    
    	CONSTRUCT_JUMP(JNB, JNB);
    	CONSTRUCT_JUMP(JAE, JNB);
    	CONSTRUCT_JUMP(JAZ, JNB);
    	CONSTRUCT_JUMP(JNC, JNB);
    
    	CONSTRUCT_JUMP(JBE, JBZ);
    	CONSTRUCT_JUMP(JBZ, JBZ);
    	CONSTRUCT_JUMP(JNA, JBZ);
    
    	CONSTRUCT_JUMP(JA, JA);
    	CONSTRUCT_JUMP(JNBE, JA);
    	CONSTRUCT_JUMP(JNBZ, JA);
    
    	CONSTRUCT_JUMP(CALL, CALL);
    #undef CONSTRUCT_JUMP

    kcalbCube, 01 Марта 2022

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

    0

    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
    #define CONSTRUCT_JUMP(name_, opcode_) else if(mnemonic.name == #name_) \
    	subcompileMnemonic(mnemonic, {\
    	{constructDescription(CONSTANT), opcode_},\
    	{constructDescription(LABEL), opcode_}})
    
    	CONSTRUCT_JUMP(JMP, JMP);
    
    	CONSTRUCT_JUMP(JE, JZ);
    	CONSTRUCT_JUMP(JZ, JZ);
    
    	CONSTRUCT_JUMP(JNZ, JNZ);
    	CONSTRUCT_JUMP(JNE, JNZ);
    
    	CONSTRUCT_JUMP(JG, JG);
    	CONSTRUCT_JUMP(JNLE, JG);
    	CONSTRUCT_JUMP(JNLZ, JG);
    
    	CONSTRUCT_JUMP(JLE, JNG);
    	CONSTRUCT_JUMP(JLZ, JNG);
    	CONSTRUCT_JUMP(JNG, JNG);
    
    	CONSTRUCT_JUMP(JGE, JGZ);
    	CONSTRUCT_JUMP(JGZ, JGZ);
    	CONSTRUCT_JUMP(JNL, JGZ);
    
    	CONSTRUCT_JUMP(JNGZ, JL);
    	CONSTRUCT_JUMP(JNGE, JL);
    	CONSTRUCT_JUMP(JL  , JL);
    
    	CONSTRUCT_JUMP(JB, JB);
    	CONSTRUCT_JUMP(JNAE, JB);
    	CONSTRUCT_JUMP(JNAZ, JB);
    	CONSTRUCT_JUMP(JC, JB);
    
    	CONSTRUCT_JUMP(JNB, JNB);
    	CONSTRUCT_JUMP(JAE, JNB);
    	CONSTRUCT_JUMP(JAZ, JNB);
    	CONSTRUCT_JUMP(JNC, JNB);
    
    	CONSTRUCT_JUMP(JBE, JBZ);
    	CONSTRUCT_JUMP(JBZ, JBZ);
    	CONSTRUCT_JUMP(JNA, JBZ);
    
    	CONSTRUCT_JUMP(JA, JA);
    	CONSTRUCT_JUMP(JNBE, JA);
    	CONSTRUCT_JUMP(JNBZ, JA);
    
    	CONSTRUCT_JUMP(CALL, CALL);
    #undef CONSTRUCT_JUMP

    kcalbCube, 01 Марта 2022

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

    +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
    constexpr int add(int a, int b) 
    {
        return a + b;
    }
    
    static_assert(1 |> add(2) == and(1, 2));
    
    FILE* file = fopen( “a.txt”, “wb” );
    if (file) {
        fputs(“Hello world”, file);
        file |> fseek(9, SEEK_SET);
        file |> fclose();
    }
    
    auto dangerous_teams(std::string const& s) -> bool {
        return s
             |> views::group_by(std::equal_to{})
             |> views::transform(ranges::distance)
             |> ranges::any_of([](std::size_t s){
                    return s >= 7;
                });
    }

    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2011r0.html

    какой C++)))

    kcalbCube, 19 Февраля 2022

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

    +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
    #include <stdio.h>
    #include <stdint.h>
    
    int main(void)
    {
    	bool a = 0;
    	*((uint8_t*)&a) = 2;
    	if(!a)
    		printf("a false\n");
    	else
    		printf("a true\n");
    
    	return 0;
    
    }
    
    ------
    .LC1:
            .string "a true"
    main:
            push    rax
            mov     edi, OFFSET FLAT:.LC1
            call    puts
            xor     eax, eax
            pop     rdx
            ret

    какой ID)))

    digitalEugene, 15 Февраля 2022

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

    0

    1. 1
    std::tie(v[0], v[1]) = std::make_tuple(v[1], v[0])

    какой swap)))

    digitalEugene, 11 Февраля 2022

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