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

    +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
    static char *cast_table[][11] = {
      // i8   i16     i32     i64     u8     u16     u32     u64     f32     f64     f80
      {NULL,  NULL,   NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i8
      {i32i8, NULL,   NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i16
      {i32i8, i32i16, NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i32
      {i32i8, i32i16, NULL,   NULL,   i32u8, i32u16, NULL,   NULL,   i64f32, i64f64, i64f80}, // i64
    
      {i32i8, NULL,   NULL,   i32i64, NULL,  NULL,   NULL,   i32i64, i32f32, i32f64, i32f80}, // u8
      {i32i8, i32i16, NULL,   i32i64, i32u8, NULL,   NULL,   i32i64, i32f32, i32f64, i32f80}, // u16
      {i32i8, i32i16, NULL,   u32i64, i32u8, i32u16, NULL,   u32i64, u32f32, u32f64, u32f80}, // u32
      {i32i8, i32i16, NULL,   NULL,   i32u8, i32u16, NULL,   NULL,   u64f32, u64f64, u64f80}, // u64
    
      {f32i8, f32i16, f32i32, f32i64, f32u8, f32u16, f32u32, f32u64, NULL,   f32f64, f32f80}, // f32
      {f64i8, f64i16, f64i32, f64i64, f64u8, f64u16, f64u32, f64u64, f64f32, NULL,   f64f80}, // f64
      {f80i8, f80i16, f80i32, f80i64, f80u8, f80u16, f80u32, f80u64, f80f32, f80f64, NULL},   // f80
    };

    красивое

    kcalbCube, 26 Февраля 2022

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

    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
    // Takes a printf-style format string and returns a formatted string.
    char *format(char *fmt, ...) {
      char *buf;
      size_t buflen;
      FILE *out = open_memstream(&buf, &buflen);
    
      va_list ap;
      va_start(ap, fmt);
      vfprintf(out, fmt, ap);
      va_end(ap);
      fclose(out);
      return buf;
    }

    kcalbCube, 25 Февраля 2022

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

    −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
    typedef enum {
      FILE_NONE, FILE_C, FILE_ASM, FILE_OBJ, FILE_AR, FILE_DSO,
    } FileType;
    
    StringArray include_paths;
    bool opt_fcommon = true;
    bool opt_fpic;
    
    static FileType opt_x;
    static StringArray opt_include;
    static bool opt_E;
    static bool opt_M;
    static bool opt_MD;
    static bool opt_MMD;
    static bool opt_MP;
    static bool opt_S;
    static bool opt_c;
    static bool opt_cc1;
    static bool opt_hash_hash_hash;
    static bool opt_static;
    static bool opt_shared;
    static char *opt_MF;
    static char *opt_MT;
    static char *opt_o;
    
    static StringArray ld_extra_args;
    static StringArray std_include_paths;
    
    char *base_file;
    static char *output_file;
    
    static StringArray input_paths;
    static StringArray tmpfiles;

    благо поиск по проекту работает

    kcalbCube, 25 Февраля 2022

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

    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
    void pong_game(void)
       {
          /*Set the first random direction the ball will be traviling*/
          direction=random_direction();
          
          /*Play the game while the ESC key is not pressed*/
          while(!key[KEY_ESC]) {
             /*Move the Ball*/
             move_ball();
             /*Respond to the input*/
             key_respond();
             
             /*Put the information on the Screen*/
             textout(buffer,pong_datafile[pong_text].dat,"Player 1 Score:",
                     150,0,254);
             textout(buffer,pong_datafile[pong_text].dat,itoa(score_p1,NULL,10),
                     text_length(pong_datafile[pong_text].dat,
                     "Player 1 Score:")+150,0,10);
             textout(buffer,pong_datafile[pong_text].dat,"Player 2 Score:",
                     350,0,254);
             textout(buffer,pong_datafile[pong_text].dat,itoa(score_p2,NULL,10),
                     text_length(pong_datafile[pong_text].dat,
                                 "Player 2 Score:")+350,0,10);
             textout(buffer,pong_datafile[pong_text].dat,"keyboard",0,0,255);
             textout(buffer,pong_datafile[pong_text].dat,"joystick",
                     640-text_length(pong_datafile[pong_text].dat,"joystick"),
                     0,255);
             /*Draw a line to set the boundries*/
             line(buffer,0,30,640,30,10);
             
             /*Put the buffer screen on the screen*/
             blit(buffer,screen,0,0,0,0,640,480);
             
             /*Clear the buffer*/
             clear(buffer);
          }
          return;
       }

    помните?

    kcalbCube, 20 Февраля 2022

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

    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
    #define debut     {
    #define fin       }
    #define si        if
    #define alors     {
    #define sinon     } else {
    #define sinonsi   } else if
    
    #define repeter   do {
    #define jusqua    } while (!
    
    #define choix     switch
    #define quand     case
    
    #define retourner return

    какой gaffe))

    kcalbCube, 19 Февраля 2022

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

    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
    #include <stdio.h>
    #include <setjmp.h>
    #include <assert.h>
    
    jmp_buf ebuf;
    
    void f2(void)
    {
    	longjmp(ebuf, (int)"kokoko");
    }
    
    int main(void)
    {
    	const char* i;
    	printf("petuhi ");
    	i = (const char*)setjmp(ebuf);
    	if (!i) 
    	{
    		f2();
    		printf ("moo ");
    	}
    	printf("%s\n", i);
    	return 0;
    }

    можно елду сделать

    digitalEugene, 14 Февраля 2022

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

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    // https://sources.debian.org/src/bsdiff/4.3-23/bsdiff.c/#L57
    
    static void split(t_off *I,t_off *V,t_off start,t_off len,t_off h)
    {
    	t_off i,j,k,x,tmp,jj,kk;
    
    	if(len<16) {
    		for(k=start;k<start+len;k+=j) {
    			j=1;x=V[I[k]+h];
    			for(i=1;k+i<start+len;i++) {
    				if(V[I[k+i]+h]<x) {
    					x=V[I[k+i]+h];
    					j=0;
    				};
    				if(V[I[k+i]+h]==x) {
    					tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
    					j++;
    				};
    			};
    			for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
    			if(j==1) I[k]=-1;
    		};
    		return;
    	};
    
    	x=V[I[start+len/2]+h];
    	jj=0;kk=0;
    	for(i=start;i<start+len;i++) {
    		if(V[I[i]+h]<x) jj++;
    		if(V[I[i]+h]==x) kk++;
    	};
    	jj+=start;kk+=jj;
    
    	i=start;j=0;k=0;
    	while(i<jj) {
    		if(V[I[i]+h]<x) {
    			i++;
    		} else if(V[I[i]+h]==x) {
    			tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
    			j++;
    		} else {
    			tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	while(jj+j<kk) {
    		if(V[I[jj+j]+h]==x) {
    			j++;
    		} else {
    			tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
    			k++;
    		};
    	};
    
    	if(jj>start) split(I,V,start,jj-start,h);
    
    	for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
    	if(jj==kk-1) I[jj]=-1;
    
    	if(start+len>kk) split(I,V,kk,start+len-kk,h);
    }
    
    static void qsufsort(t_off *I,t_off *V,u_char *old,t_off oldsize)
    {
    	t_off buckets[256];
    	t_off i,h,len;
    
    	for(i=0;i<256;i++) buckets[i]=0;
    	for(i=0;i<oldsize;i++) buckets[old[i]]++;
    	for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
    	for(i=255;i>0;i--) buckets[i]=buckets[i-1];
    	buckets[0]=0;
    
    	for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
    	I[0]=oldsize;
    	for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
    	V[oldsize]=0;
    	for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
    	I[0]=-1;
    
    	for(h=1;I[0]!=-(oldsize+1);h+=h) {
    		len=0;
    		for(i=0;i<oldsize+1;) {
    			if(I[i]<0) {
    				len-=I[i];
    				i-=I[i];
    			} else {
    				if(len) I[i-len]=-len;
    				len=V[I[i]]+1-i;
    				split(I,V,i,len,h);
    				i+=len;
    				len=0;
    			};
    		};
    		if(len) I[i-len]=-len;
    	};
    
    	for(i=0;i<oldsize+1;i++) I[V[i]]=i;
    }

    Исходник "bsdiff"

    j123123, 02 Февраля 2022

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

    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
    int main(int argc, char **argv) {
      void *vp;
      const char *version_str;
    
      if (argc != 2) {
        fprintf(stderr, "usage: %s <version>\n", argv[0]);
        exit(1);
      }
    
      vp = malloc(strlen(argv[1]) + 1);
      strcpy(vp, argv[1]);
    
      version_str = check_header(vp);
      free(vp);
    
      printf("0.%s\n", version_str);
    
      return 0;
    }

    Там Беллард с научил вореции программировать на Сишке

    https://textsynth.com/playground.html

    3.14159265, 31 Января 2022

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

    0

    1. 1
    #define mbarrier() asm volatile ("":::"memory")

    HoBorogHuu_nemyx, 30 Января 2022

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

    +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
    // тред лоулевел-хаков #1
    
    #include <stdio.h>
    #include <stdlib.h>
    
    void hello(void)
    {
            puts("Hello!");
    }
    
    void goodbye(void)
    {
            puts("Goodbye!");
    }
    
    void set_sp_(void *p)
    {
            void *s[0];
            s[0] = p;
    }
    
    void set_sp(void *p)
    {
            set_sp_((void*)p);
    }
    
    int main(void)
    {
            void *new_stack[1024] = {
                    [1019] = (void*)0,
                    [1020] = (void*)&hello,
                    [1021] = (void*)&goodbye,
                    [1022] = (void*)&exit
            };
            set_sp((void*)&new_stack[1019]);
            return 0;
    }

    UB-ы, платформенно зависимый кот, битовая магия

    всё сюда
    |
    |
    \/

    Hu3KoypoBHeBblunemyx, 28 Января 2022

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