1. 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)
  2. 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)
  3. 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

    Комментарии (29)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. C++ / Говнокод #28006

    0

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

    какой swap)))

    digitalEugene, 11 Февраля 2022

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

    0

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

    какой swap)))

    digitalEugene, 11 Февраля 2022

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

    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
    #define OPCODEFORMAT_CASE(opcode, format) case opcode: return format; break
    inline OpcodeFormat getOpcodeFormat(Opcode opcode)
    {
    	switch (opcode)
    	{
    		OPCODEFORMAT_CASE(NOP		, OPCODE);
    		OPCODEFORMAT_CASE(MOV_RR	, OPCODE_RR);
    		OPCODEFORMAT_CASE(MOV_RC	, OPCODE_RC);
    		OPCODEFORMAT_CASE(MOV_RM	, OPCODE_RM);
    		OPCODEFORMAT_CASE(MOV_MR	, OPCODE_MR);
    		OPCODEFORMAT_CASE(MOV_MC	, OPCODE_MC);
    		OPCODEFORMAT_CASE(MOV_MM	, OPCODE_MM);
    		OPCODEFORMAT_CASE(ADD		, OPCODE_RR);
    		OPCODEFORMAT_CASE(SUB		, OPCODE_RR);
    		OPCODEFORMAT_CASE(ADD_C	, OPCODE_RC);
    		OPCODEFORMAT_CASE(SUB_C		, OPCODE_RC);
    		OPCODEFORMAT_CASE(MUL		, OPCODE_RR);
    		OPCODEFORMAT_CASE(DIV		, OPCODE_RR);
    		OPCODEFORMAT_CASE(MUL_C	, OPCODE_RC);
    		OPCODEFORMAT_CASE(DIV_C		, OPCODE_RC);
    		OPCODEFORMAT_CASE(LEA		, OPCODE_RM);
    		OPCODEFORMAT_CASE(INC		, OPCODE_R);
    		OPCODEFORMAT_CASE(DEC		, OPCODE_R);
    		OPCODEFORMAT_CASE(INT		, OPCODE_C8);
    		OPCODEFORMAT_CASE(CMP_RC	, OPCODE_RC);
    		OPCODEFORMAT_CASE(JMP		, OPCODE_C);
    		OPCODEFORMAT_CASE(JZ		        , OPCODE_C);
    		OPCODEFORMAT_CASE(JNZ		, OPCODE_C);
    		OPCODEFORMAT_CASE(JG		, OPCODE_C);
    		OPCODEFORMAT_CASE(JNG		, OPCODE_C);
    		OPCODEFORMAT_CASE(JGZ		, OPCODE_C);
    		OPCODEFORMAT_CASE(JL		        , OPCODE_C);
    		OPCODEFORMAT_CASE(CALL		, OPCODE_C);
    		OPCODEFORMAT_CASE(PUSH_R	, OPCODE_R);
    		OPCODEFORMAT_CASE(PUSH_C	, OPCODE_C);
    		OPCODEFORMAT_CASE(PUSH_C8	, OPCODE_C8);
    		OPCODEFORMAT_CASE(POP_R	, OPCODE_R);
    		OPCODEFORMAT_CASE(POP		, OPCODE);
    		OPCODEFORMAT_CASE(POP8		, OPCODE);
    		OPCODEFORMAT_CASE(POP_M8	, OPCODE_M);
    		OPCODEFORMAT_CASE(POP_M16	, OPCODE_M);
    		OPCODEFORMAT_CASE(OUT_M8	, OPCODE_MC);
    		OPCODEFORMAT_CASE(OUT_M16	, OPCODE_MC);
    		OPCODEFORMAT_CASE(OUT_C8	, OPCODE_CC8);
    		OPCODEFORMAT_CASE(OUT_C16	, OPCODE_CC);
    		OPCODEFORMAT_CASE(OUT_R	, OPCODE_RC);
    		OPCODEFORMAT_CASE(IN_R		, OPCODE_RC);
    		OPCODEFORMAT_CASE(IN_M8	, OPCODE_MC);
    		OPCODEFORMAT_CASE(IN_M16	, OPCODE_MC);
    		OPCODEFORMAT_CASE(RET		, OPCODE);
    
    	default: return (OpcodeFormat)0xFF; break;
    	}
    }
    #undef OPCODEFORMAT_CASE

    отрефакторил

    digitalEugene, 10 Февраля 2022

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