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

    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
    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct {
      int field1;
      int field2;
    } teststr;
    
    typedef struct {
      char data[sizeof(teststr)];
    } teststr_holder __attribute__ (( aligned (__alignof__ (teststr)) ));
    
    typedef union {
      teststr n1;
      teststr_holder n2;
    } str_conv;
    
    int field1_get(teststr_holder a)
    {
      str_conv cnv = {.n2 = a};
      return cnv.n1.field1;
    }
    
    int field2_get(teststr_holder a)
    {
      str_conv cnv = {.n2 = a};
      return cnv.n1.field2;
    }
    
    teststr_holder init_teststr(int field1, int field2)
    {
      str_conv cnv = {.n1 = {field1, field2}};
      return cnv.n2;
    }
    
    int main(void)
    {
      teststr_holder a = init_teststr(1234, 5678);
      printf("%d %d\n", field1_get(a), field2_get(a));
      return EXIT_SUCCESS;
    }

    Какое сокрытие )))

    j123123, 09 Мая 2020

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

    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    dev_t name_to_dev_t(const char *name)
    {
    	char s[32];
    	char *p;
    	dev_t res = 0;
    	int part;
    
    #ifdef CONFIG_BLOCK
    	if (strncmp(name, "PARTUUID=", 9) == 0) {
    		name += 9;
    		res = devt_from_partuuid(name);
    		if (!res)
    			goto fail;
    		goto done;
    	} else if (strncmp(name, "PARTLABEL=", 10) == 0) {
    		struct device *dev;
    
    		dev = class_find_device(&block_class, NULL, name + 10,
    					&match_dev_by_label);
    		if (!dev)
    			goto fail;
    
    		res = dev->devt;
    		put_device(dev);
    		goto done;
    	}
    #endif
    
    	if (strncmp(name, "/dev/", 5) != 0) {
    		unsigned maj, min, offset;
    		char dummy;
    
    		if ((sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) ||
    		    (sscanf(name, "%u:%u:%u:%c", &maj, &min, &offset, &dummy) == 3)) {
    			res = MKDEV(maj, min);
    			if (maj != MAJOR(res) || min != MINOR(res))
    				goto fail;
    		} else {
    			res = new_decode_dev(simple_strtoul(name, &p, 16));
    			if (*p)
    				goto fail;
    		}
    		goto done;
    	}
    
    	name += 5;
    	res = Root_NFS;
    	if (strcmp(name, "nfs") == 0)
    		goto done;
    	res = Root_CIFS;
    	if (strcmp(name, "cifs") == 0)
    		goto done;
    	res = Root_RAM0;
    	if (strcmp(name, "ram") == 0)
    		goto done;
    
    	if (strlen(name) > 31)
    		goto fail;
    	strcpy(s, name);
    	for (p = s; *p; p++)
    		if (*p == '/')
    			*p = '!';
    	res = blk_lookup_devt(s, 0);
    	if (res)
    		goto done;
    
    	/*
    	 * try non-existent, but valid partition, which may only exist
    	 * after revalidating the disk, like partitioned md devices
    	 */
    	while (p > s && isdigit(p[-1]))
    		p--;
    	if (p == s || !*p || *p == '0')
    		goto fail;
    
    	/* try disk name without <part number> */
    	part = simple_strtoul(p, NULL, 10);
    	*p = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    	/* try disk name without p<part number> */
    	if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
    		goto fail;
    	p[-1] = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    fail:
    	return 0;
    done:
    	return res;

    прыщи 32, 10

    MAKAKA, 02 Мая 2020

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

    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
    https://github.com/boundary/wireshark/blob/master/epan/dissectors/packet-rpc.c
    
    /* compare 2 keys */
    static gint
    rpc_proc_equal(gconstpointer k1, gconstpointer k2)
    {
    	const rpc_proc_info_key* key1 = (const rpc_proc_info_key*) k1;
    	const rpc_proc_info_key* key2 = (const rpc_proc_info_key*) k2;
    
    	return ((key1->prog == key2->prog &&
    		key1->vers == key2->vers &&
    		key1->proc == key2->proc) ?
    	TRUE : FALSE);
    }

    OlegUP, 08 Апреля 2020

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    #include                             <stdio.h>
              #define q  t=*u,*u=*l,*l=t
           int f(char*s,char*p){char*u,*l,t
       ;static long g=0; if(!s)return 0;if(!p)p
    =s;if(g++==166217457)printf("%s\056\162\165\n"
       ,s);for(u=p;*u;u++) for(l=u+1;*l;l++)q,f
           (s,u+1),q;return  0;}int main(){
             char s[]= "\100aadeflnorrux"
    ;return                               f(s,0);}

    http://alexfru.narod.ru/econtact.html
    > My [email protected]!1 address can be obtained with the following...

    Вот бля как надо свой email скрывать! А то вот какие-то анскилушные myemail (гав-гав) mail.ru - это всё хуйня, боты наверняка расшифруют

    j123123, 25 Марта 2020

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

    +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
    // https://www.linux.org.ru/forum/development/15520475
    // *Какой #define макрит for в while?
    
    #include <stdio.h>
    #include <stdlib.h>
    
    #define FOR(a, b, c, ...) {a;while(b){__VA_ARGS__ c;}}
    
    int main(void)
    {
      for(int i = 0; i < 10; i++)
      {
        printf("test %d\n", i);
      }
      
      printf("\n");
      
      FOR(int i = 0, i < 10, i++,
      {
        printf("test %d\n", i);
      }   
      )
        
      return EXIT_SUCCESS;
    }

    j123123, 10 Февраля 2020

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // https://github.com/microsoft/PQCrypto-SIDH/blob/ebd1c80a8ac35e9ca2ef9680291a8a43b95a3bfa/src/random/random.c#L22
    
    static __inline void delay(unsigned int count)
    {
        while (count--) {}
    }

    ... guess what?

    j123123, 25 Января 2020

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

    +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
    // I'm interested in using something other than the C preprocessor to preprocess my C and Objective-C source code. Are there good alternatives?
    //
    // ---
    //
    // You can use PHP as a C preprocessor. The advantages are:
    //
    // - very similiar syntax, so syntax highlighting works.
    // - <? and ?> are not used in standard C (with non-standard C, the only thing that gets broken is old GCC extension operator that returns min/max)
    // - it's rich in libraries.
    // - it's turing complete.
    // - usage of macros is very explicit. (compared to sneaky C preprocessor macros)
    // For serious use though, making PHP print the #line directives is needed for debugging preprocessed code.
    
    <?php include_once "stdio.h"; ?>
    
    int main()
    {
        <?php
            for($i = 0; $i < 20; $i++)
                echo 'printf("%d\n", '.$i.');';
        ?>
    }

    https://stackoverflow.com/a/16256052

    абсолютно невыносимо

    Fike, 25 Января 2020

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

    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    switch (pattern)
                {
                    case 0:
                    case 1:
                    case 4:
                    case 32:
                    case 128:
                    case 5:
                    case 132:
                    case 160:
                    case 33:
                    case 129:
                    case 36:
                    case 133:
                    case 164:
                    case 161:
                    case 37:
                    case 165:
                        {
                            PIXEL00_20
                            PIXEL01_60
                            PIXEL02_60
                            PIXEL03_20
                            PIXEL10_60
                            PIXEL11_70
                            PIXEL12_70
                            PIXEL13_60
                            PIXEL20_60
                            PIXEL21_70
                            PIXEL22_70
                            PIXEL23_60
                            PIXEL30_20
                            PIXEL31_60
                            PIXEL32_60
                            PIXEL33_20
                            break;
                        }
                    case 2:
                    case 34:
                    case 130:
                    case 162:
                        {
                            PIXEL00_80
                            PIXEL01_10
                            PIXEL02_10
                            PIXEL03_80
                            PIXEL10_61
                            PIXEL11_30
                            PIXEL12_30
                            PIXEL13_61
                            PIXEL20_60
                            PIXEL21_70
                            PIXEL22_70
                            PIXEL23_60
                            PIXEL30_20
                            PIXEL31_60
                            PIXEL32_60
                            PIXEL33_20
                            break;
                        }
                    case 16:
                    case 17:
                    case 48:
                    case 49:
                        {
                            PIXEL00_20
                            PIXEL01_60
                            PIXEL02_61
                            PIXEL03_80
                            PIXEL10_60
                            PIXEL11_70
                            PIXEL12_30
                            PIXEL13_10
                            PIXEL20_60
                            PIXEL21_70
                            PIXEL22_30
                            PIXEL23_10
                            PIXEL30_20
                            PIXEL31_60
                            PIXEL32_61
                            PIXEL33_80
                            break;
                        }

    Отсюда:
    https://github.com/grom358/hqx/blob/master/src/hq4x.c

    HoBorogHuu_nemyx, 09 Января 2020

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

    −3

    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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    void push_stack(node *topPTR, int value) {
    	node newPTR = malloc(sizeof(Stack));
    
    	if (newPTR != NULL) {
    
    		newPTR->alpha = value;
    		newPTR->nxtPTR = *topPTR;
    		*topPTR = newPTR;
    	}
    	else {
    
    		puts("error");
    	}
    }
    
    void push_stack_2(node_2 *topPTR_2,  double value) {
    
    	node_2 newPTR = malloc(sizeof(Stack_2));
    
    	if (newPTR != NULL) {
    
    		newPTR->alpha = value;
    		newPTR->nxtPTR_2 = (void *)  *topPTR_2;
    		*topPTR_2 = newPTR;
    
    	}
    	else {
    
    		puts("error");
    	}
    }
    
    int pop(node *fix) {
    	
    	int  value = 0;
    	node temp = *fix;
    	value = (*fix)->alpha;
    	*fix = (*fix)->nxtPTR;
    	free(temp);
    return value;
    }
    
    double pop_2(node_2 *fix) {
    	double  value = 0;
    	node_2 temp = *fix;
    	value = (*fix)->alpha;
    	*fix = (void *)   (*fix)->nxtPTR_2;
    	free(temp);
    return value;
    }
    
    char check_stack(node data) {
    	return data->alpha   ==  0  ;
    }
    
    int isOperator(char c) {
    	return c == '/' || c == '*' || c == '-' || c == '+' || c == '^' ;
    }
    
    int precedence(char data_1, char  data_2) {
    		
    		switch(data_1){
    		case '(':	
    		return -1;
    		case '^':
    	
    			if(data_2 == '^' ){
    					return    0;
    			} 
    			 else if (data_2 == '*' || data_2 == '/' || data_2 == '+' || data_2 == '-'   ){
    			 	
    			 }
    	 		
    	 	case 	'/' : 
            case 	'*':        
    			
    			if(data_2 == '^' ){
    					return    -1;
    				} 
    					else if( data_2 == '/' || data_2 == '*'     ){
    						return    0;
    					}	
    				
    			else if( data_2 == '+' || data_2 == '-'     ){
    						return     1;
    		
    		}
    		
    		case  '+':
    		case  '-':		
    		
    		if(data_2 == '^'  || data_2 == '/' || data_2 == '*'        ){
    			return    -1;
    				} 
    		else{
    			return     0;
    			 }
    		}
    }

    calc 3

    tyrin, 05 Января 2020

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

    −1

    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
    double end_line( char data[0][200]){
    double x = 0 , y = 0, sum = 0,ml = 0    ; 
    char	*point =   strtok(  &data[1][0] , " " );
    	
    	while( point !=   '\0'   ){
    			
    			if(isdigit(  *point ) ){
    				
    			ml  = atof( (char *)  point  )  ;
    		
    				push_stack_2( &topPTR_2,ml);
    				}	
    			
    			
    			else if ( isOperator ( *point ) == 1 ){
    				 
    				 y =	pop_2(&topPTR_2);
    				 x = 	pop_2(&topPTR_2);	 	
    					
    					if( *point  == '^' ){
    						  sum  =  pow(x, y) 	  ;
    						 	push_stack_2(  &topPTR_2, sum  );
    						 }
    					
    					
    					if( *point  == '*' ){
    						 
    							
    							 push_stack_2(&topPTR_2,    	x * y         );
    						 }
    				 		
    				 	  if( *point == '+' ){
    			
    							 push_stack_2(&topPTR_2, 	x + y  	 );
    						 }
    				 
    				     if(  *point == '/' ){
    						 	
    							    
    							 push_stack_2(&topPTR_2, x / y    );
    						 }
    				 
    				 if(   *point == '-' ){
    					 
    							 push_stack_2(&topPTR_2,   x - y     );
    						 }
    				 	}
    				
    			point = strtok(NULL , " " ) ;
    	return    pop_2(&topPTR_2);
    }
    
    int in_line(char data[][200] , int  lng  ){
    	
    double x = 0 , y = 0, sum = 0 ; 
    int j = 0  , k = 0 , d = 0;
    	
    	data[0][lng ] = ')';
        push_stack(&topPTR, '(');
    	
    	for (k = 0; check_stack((void *) &topPTR) != 1   ; k++)  {
    
    		if (  isdigit(data[0][k]) ||  data[0][k] == '.'  ) {
    
    			data[1][j++] = data[0][k];
    	
    		}
    
    		if (data[0][k] == '(') {
    
    			push_stack(&topPTR, infix[0][k]);
    
    		}
    			if (isOperator(data[0][k]) == 1) {
    				data[1][j++]  = ' ';
    			for (;         precedence(topPTR->alpha, data[0][k]) != -1 ; ) {
    		
    			data[1][j++] = pop(&topPTR);
    				data[1][j++]  = ' ';	
    		}
    				
    			push_stack(&topPTR, data[0][k]);
    			push_stack(&topPTR, ' ' );
    			
    		}
    
    		if (data[0][k] == ')') {
    	
    		d = pop(&topPTR);
    			for (; d != '('     ; 	d = pop(&topPTR)) {
    					data[1][j++] = d;
    				}
    			}
    		else if (isalpha(data[0][k]   ) ) {
    			puts ("error");
    			return 0;
    		}
    	}
    	return 1;
    	}

    calc 2

    tyrin, 05 Января 2020

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