1. Си / Говнокод #25423

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #include <stdio.h>
    
    int main(void)
    {
        int a = a;
        printf("%d", a);
        return 0;
    }

    Убрал ворнинг. Проверь.

    https://tio.run/##[email protected]/185My85pzQlVcGmuCQlM18vw46LKzOvRCE3MTNPoyw/M0WTq5pLAQhAgokKtgqJ1mBuQRFQIE1DSTVFSUchURMiWJRaUlqUp2BgzVXL9f//[email protected]@64Yk5OQA

    BEKTOPHblu_nETyX, 04 Марта 2019

    Комментарии (94)
  2. Си / Говнокод #25399

    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
    // https://github.com/ghc/ghc/blob/e204431e5a5e2fd16da52b04bda2798f16c51344/rts/Interpreter.c#L1184
    
            case bci_PUSH8: {
                int off = BCO_NEXT;
                Sp_subB(1);
                *(StgWord8*)Sp = *(StgWord8*)(Sp_plusB(off+1));
                goto nextInsn;
            }
    
            case bci_PUSH16: {
                int off = BCO_NEXT;
                Sp_subB(2);
                *(StgWord16*)Sp = *(StgWord16*)(Sp_plusB(off+2));
                goto nextInsn;
            }
    
            case bci_PUSH32: {
                int off = BCO_NEXT;
                Sp_subB(4);
                *(StgWord32*)Sp = *(StgWord32*)(Sp_plusB(off+4));
                goto nextInsn;
            }
    
            case bci_PUSH8_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord8*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }
    
            case bci_PUSH16_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord16*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }
    
            case bci_PUSH32_W: {
                int off = BCO_NEXT;
                *(StgWord*)(Sp_minusW(1)) = *(StgWord32*)(Sp_plusB(off));
                Sp_subW(1);
                goto nextInsn;
            }

    https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts/Interpreter

    > The linker lives in rts/Linker.c and is responsible for handling runtime loading of code into a Haskell process. This is something of a big blob of unpleasant code, and see DynamicGhcPrograms for information about efforts to reduce our dependence on this linker.

    Итак, тут у нас стековая машина из хачкеля, которая вродекак отвечает за динамическую загрузку какого-то говна.

    j123123, 22 Февраля 2019

    Комментарии (92)
  3. Си / Говнокод #25397

    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
    // https://github.com/alpertron/calculators/blob/15607feafb0ddb1c075bb326dc6ea2224a4c50bb/siqs.c#L3720
    
                switch (NumberLengthA)
                {
                case 7:
                  dRem = (double)*(piDividend + 6) * (double)rowPrimeTrialDivisionData->exp6 +
                    (double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
                    (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 6:
                  dRem = (double)*(piDividend + 5) * (double)rowPrimeTrialDivisionData->exp5 +
                    (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 5:
                  dRem = (double)*(piDividend + 4) * (double)rowPrimeTrialDivisionData->exp4 +
                    (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                case 4:
                  dRem = (double)*(piDividend + 3) * (double)rowPrimeTrialDivisionData->exp3 +
                    (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                default:
                  dRem = (double)*(piDividend + 2) * (double)rowPrimeTrialDivisionData->exp2 +
                    (double)*(piDividend + 1) * (double)rowPrimeTrialDivisionData->exp1;
                  break;
                }

    Generic two integer variable equation solver
    This calculator can solve equations of the form a⁢x² + b⁢x⁢y + c⁢y² + dx + ey + f = 0 where the unknowns x and y are integer numbers.

    j123123, 22 Февраля 2019

    Комментарии (6)
  4. Си / Говнокод #25375

    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
    // https://git.zx2c4.com/BruteZip/tree/read.c?id=e4e9c17b99e0d108136b8a07632b1ebaa7d09d28#n26
    
    int main(int argc, char *argv[])
    {
    	union {
    		long int l;
    		char c[sizeof(long int)];
    	} u;
    	u.l = 1;
    	if (u.c[sizeof(long int) - 1] == 1) {
    		printf("This program only runs on little endian archs, because I'm lazy. Sorry.\n");
    		return -2;
    	}

    Хуйня какая-то. Ведь sizeof(long int) может быть равен sizeof(char).

    Но над такой питушней обычно никто не задумывается

    j123123, 13 Февраля 2019

    Комментарии (219)
  5. Си / Говнокод #25372

    −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
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    // http://p99.gforge.inria.fr/p99-html/group__flexible.html
    
    //C99 allows a flexible array member to be defined as the last member of a struct,
    // namely an array of undetermined length.
    //P99_DECLARE_STRUCT(package_head);
    
    struct package_head {
      char name[20];
      size_t len;
      uint64_t data[];
    };
    
    // Such a struct can then be allocated on the heap with a suitable size such 
    // that the field data has as many elements as fit in the allocated space from
    // the start of data onward. Usually one would allocate such struct with
    
    package_head *a = malloc(sizeof(package_head) + 10 * sizeof(uint64_t));
    package_head *b = malloc(sizeof(*b) + 12 * sizeof(b->data[0]));
    
    // This has several disadvantages. Firstly, the syntax is clumsy. We have to
    // use a relatively complicated expression that uses two elements of the specification of a or b.
    
    // Secondly, it wastes space. Due to packing of the struct the offset of data "inside"
    //  the struct may be less than sizeof(package_head). In most cases the real size
    // of the object that we want to construct is
    
    offsetof(package_head, data) + N * sizeof(uint64_t)
    
    // so we are wasting
    
    sizeof(package_head) - offsetof(package_head, data)
    
    // bytes.
    
    // The above formula for the exact size is only valid for larger values of N. We must
    // also ensure that we allocate at least sizeof(package_head) bytes. So the complete
    // formula looks something like
    
    #define P99_FSIZEOF(T, F, N) P99_MAXOF(sizeof(T), offsetof(T, F) + P99_SIZEOF(T, F[0]) * N)
    
    // which is probably not something that you want to write on a daily basis.
    
    // We provide several interfaces to allocate struct with flexible members

    Херню написали какую-то. Забыли самое главное : нельзя так в лоб аллоцировать память под структуры. Потому что выравнивание может не то быть.
    Надо использовать http://man7.org/linux/man-pages/man3/aligned_alloc.3.html

    j123123, 12 Февраля 2019

    Комментарии (25)
  6. Си / Говнокод #25349

    −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
    #include <stdio.h>
    #include <stdlib.h>
    #include <inttypes.h>
    
    int main(void)
    {
      char a[8], b[8];
      char *a_ptr = a+8;
      char *b_ptr = b;
      printf("a_ptr = %p, b_ptr = %p\n", a_ptr, b_ptr);
      if (a_ptr != b_ptr)
      {
        printf("a_ptr != b_ptr\n");
      }
      else
      {
        printf("a_ptr == b_ptr\n");
      }
      
      
      if ((uintptr_t)a_ptr != (uintptr_t)b_ptr)
      {
        printf("(uintptr_t)a_ptr != (uintptr_t)b_ptr\n");
      }
      else
      {
        printf("(uintptr_t)a_ptr == (uintptr_t)b_ptr\n");
      }
      return EXIT_SUCCESS;
    }

    Что по-вашему тут происходит?

    j123123, 02 Февраля 2019

    Комментарии (39)
  7. Си / Говнокод #25341

    +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
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    /*
    * Place the right command in the parameter AY temperature fine adjust
    * Uses number from PPD less 11.
    */
    switch (header->cupsCompression)
    {
    case 1 :
      strcpy(Fadjt,"{AY;-10,");
      break;
    case 2 :
      strcpy(Fadjt,"{AY;-09,");
      break;
    case 3 :
      strcpy(Fadjt,"{AY;-08,");
      break;
    case 4 :
      strcpy(Fadjt,"{AY;-07,");
      break;
    case 5 :
      strcpy(Fadjt,"{AY;-06,");
      break;
    case 6 :
      strcpy(Fadjt,"{AY;-05,");
      break;
    case 7 :
      strcpy(Fadjt,"{AY;-04,");
      break;
    case 8 :
      strcpy(Fadjt,"{AY;-03,");
      break;
    case 9 :
      strcpy(Fadjt,"{AY;-02,");
      break;
    case 10 :
      strcpy(Fadjt,"{AY;-01,");
      break;
    case 11 :
      strcpy(Fadjt,"{AY;+00,");
      break;
    case 12 :
      strcpy(Fadjt,"{AY;+01,");
      break;
    case 13 :
      strcpy(Fadjt,"{AY;+02,");
      break;
    case 14 :
      strcpy(Fadjt,"{AY;+03,");
      break;
    case 15 :
      strcpy(Fadjt,"{AY;+04,");
      break;
    case 16 :
      strcpy(Fadjt,"{AY;+05,");
      break;
    case 17 :
      strcpy(Fadjt,"{AY;+06,");
      break;
    case 18 :
      strcpy(Fadjt,"{AY;+07,");
      break;
    case 19 :
      strcpy(Fadjt,"{AY;+08,");
      break;
    case 20 :
      strcpy(Fadjt,"{AY;+09,");
      break;
    case 21 :
      strcpy(Fadjt,"{AY;+10,");
      break;
    }

    cykablyad, 31 Января 2019

    Комментарии (19)
  8. Си / Говнокод #25334

    +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
    void add_SSE(uint8_t a[static 7], uint8_t b[static 7], uint8_t out[static 7])
    {
      uint64_t a_64 = 0;
      uint64_t b_64 = 0;
      for (size_t i = 0; i < 7; i++) // можно наанроллить
      {
        a_64 |= (uint64_t)a[i] << (i*9);
        b_64 |= (uint64_t)b[i] << (i*9);
      }
      
      uint64_t c_64 = a_64 + b_64;
      
      for (size_t i = 0; i < 7; i++) // можно наанроллить
      {
        out[i] = (uint64_t)c_64 >> (i*9);
      }
    }

    SSE

    j123123, 28 Января 2019

    Комментарии (32)
  9. Си / Говнокод #25314

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    void print_line(char *s){
        for(int i = 0; i < strlen(s); i++) putchar(s[i]);
        putchar('\n');
    }

    Почему C работает медленнее чем JavaScript ?

    o8603054, 17 Января 2019

    Комментарии (91)
  10. Си / Говнокод #25307

    −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
    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
    void sort8(uint64_t a[8])
    {
      uint64_t a0;
      uint64_t a1;
      uint64_t a2;
      uint64_t a3;
      uint64_t a4;
      uint64_t a5;
      uint64_t a6;
      uint64_t a7;
     
      SORT2(a[0], a[1], a0, a1);
      SORT2(a[2], a[3], a2, a3);
      SORT2(a[4], a[5], a4, a5);
      SORT2(a[6], a[7], a6, a7);
    
      uint64_t a_tmp[8];
    
      MERGE_2_4(a0, a1, a2, a3, a_tmp[0], a_tmp[1], a_tmp[2], a_tmp[3]);
      MERGE_2_4(a4, a5, a6, a7, a_tmp[4], a_tmp[5], a_tmp[6], a_tmp[7]);
    
      uint64_t *ptra1 = &a_tmp[0];
      uint64_t *ptra2 = &a_tmp[4];
      
      for (size_t i = 0; i < 4; i++)
      {
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
      }
    
      for (size_t i = 4; i < 8; i++)
      {
        if (ptra1 == &a_tmp[4])
        {
          while (ptra2 != &a_tmp[8])
          {
            a[i++] = *ptra2;
            ptra2++;
          }
          break;
        }
        
        if (ptra2 == &a_tmp[8])
        {
          while (ptra1 != &a_tmp[4])
          {
            a[i++] = *ptra1;
            ptra1++;
          }
          break;
        }
    
    
        if (*ptra1 < *ptra2)
        {
          a[i] = *ptra1;
          ptra1++;
        }
        else
        {
          a[i] = *ptra2;
          ptra2++;
        }
    
      }
    }

    Мерж сорт, специализированный на 8 элементов. Вот доказательство корректности https://paste.debian.net/hidden/cce6d31a/

    j123123, 13 Января 2019

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