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

    −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
    // вообще, есть одна говнистая особенность сишки:
    // нельзя вернуть из функции массив хуйпойми какой длины, выделив память чисто на стеке
    // Вот например:
    
    char *a_ret (size_t len)
    {
      char *ret = alloca(len);
      memset(ret, 'a', len);
      return ret; // так нельзя
    }
    
    // т.е. надо делать как-нибудь вот так
    char *a_ret (size_t len)
    {
      char *ret = malloc(len);
      if (ret == NULL)
      {
        exit(ENOMEM);
      }
      memset(ret, 'a', len);
      return ret;
    }

    Но это ж на самом-то деле говно какое-то. Дергать аллокаторы какие-то, ради каких-то мелких кусков байтиков.
    Почему не сделать хуйни, чтоб вызываемая функция как бы приосталавливалась и просила ту функцию, которая ее вызывает, чтоб она вот такой-то alloca() сделала нужного размера в своем стекфрейме, а потом туда вот та вызванная функция байтики уже вхерачивала? Ну т.е. можно сделать отдельный свой стек для локальных переменных тех функций, которые должны уметь такую хуйню делать (т.е. просить вызвавшую их функцию "а сделай ка там себе alloca(123) и дай мне указатель, а я в него насру")
    Вообще хуйня какая-то, сишка слишком сильно сковывает всякой своей хуйней, соглашениями вызовов, всякими ABI там. То ли дело ассемблер!

    j123123, 15 Мая 2019

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

    +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
    #include <conio.h>
    
    static unsigned char bigArray[256] = {['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3,
                                          ['4'] = 4, ['5'] = 5, ['6'] = 6, ['7'] = 7,
                                          ['8'] = 8, ['9'] = 9, ['A'] = 10, ['B'] = 11,
                                          ['C'] = 12, ['D'] = 13, ['E'] = 14, ['F'] = 15 };
    void StringToByte(const char src[], unsigned char dst[]) 
    {
    	int q, u = 0;
    	for (q = 0; src[q]; q+=2) 
    	{
    		dst[u] = bigArray[src[q]] << 4;
    		if (!src[q+1]) 
    			return;
    		dst[u++] |= bigArray[src[q+1]];
    	}
    }
    
    int main()
    {
    	char string[] = "112255ACBF";
    	unsigned char bytes[5];
    	StringToByte(string, bytes);
    	int i;
    	for (i = 0; i!=sizeof(bytes); i++)
    		printf("%x ", (int)bytes[i]);
    	return 0;
    }

    Ебическая С-ла.

    Psionic, 13 Мая 2019

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

    −1

    1. 1
    // Чому можливо писати "2[i]" а можливо i "i[2]"?

    а?

    DypHuu_niBEHb, 10 Мая 2019

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

    +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
    #define paehal int i = 0; char arr[30000]; memset(arr, 0, sizeof(arr));
    #define go i++;
    #define  nozad i--;
    #define plusegg arr[i]++;
    #define minusegg arr[i]--; 
    #define vivodeg putchar(arr[i]);	
    #define tipavhile while(arr[i]){	
    #define nevhile }
    int main() {
    setlocale(0, "");
    paehal
    plusegg plusegg plusegg plusegg plusegg tipavhile plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg  go nozad minusegg nevhile go vivodeg go plusegg plusegg plusegg tipavhile go plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg plusegg go minusegg nevhile go vivodeg 
    return 0;
    }

    брайнфак на минималках
    выводит a!

    pozhiloy, 07 Мая 2019

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

    0

    1. 1
    2. 2
    (cell)data += sizeof(cell) - 1;
        (cell)data &= ~(sizeof(cell) - 1);

    Блядь, ёбаный tcc! Другие конпилеры отказываются такое конпилить. Теперь дохуя переписывать.

    Hu3KoypoBHeBblunemyx, 03 Мая 2019

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    //"вирус" в стиле кулхацкеров
    #include <stdlib.h>
    int main() {
    int i = 1;
    while( i == 1)  {
    	system("start calc");
    }
    return 0;
    }

    pozhiloy, 22 Апреля 2019

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

    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
    void  converting(char *in, char *out, node *PTR, char (checking_stack)(node), void (push)(node *topPTR, char value), int (pop)(node *fix), int (isOper)(char c), int (precedence_intro)(char data_1, char  data_2, int(intro_precedence_power)(int res_1, int  res_2)), int(intro_precedence_power)(int res_1, int  res_2)) {
    
    	int k = 0, j = 0, d = 0;
    	
    	push(PTR, '(');
    	
    	for (k = 0; checking_stack((node)PTR) != 0; k++) {
    	
    		if (isdigit(in[k])) {
    			
    			out[j++] = in[k];
    
    		}
    
    		if (in[k] == '(') {
    
    			push(PTR, in[k]);
    
    		}
    
    		if (isOper(in[k]) == 1) {
    
    			while (precedence_intro((*PTR)->alpha, in[k], intro_precedence_power) != -1) {
    
    				out[j++] = pop(PTR);
    			}
    
    			push(PTR, in[k]);
    		}
    		
    		if (in[k] == ')') {
    
    			d = pop(PTR);
    			for (; d != '('; d = pop(PTR)) {
    				out[j++] = d;
    			}
    		}
    	}
    }
    
    
    
    
    
    int precedence(char data_1, char   data_2, int(intro_precedence_power)(int res_1, int  res_2))  {
     char collection[] = "+1-1*2/2^3";	
     
     char	buf_1 = (char)strcspn(  collection , &data_1) + 1;
     char	buf_2 = (char)strcspn(collection, &data_2) + 1;
    
    	return   intro_precedence_power(atoi(&collection[buf_1]), atoi(&collection[buf_2]));
    }
    
    int precedence_power(int res_1, int  res_2) {
    	if (res_1 < res_2) {
    		return   -1;
    	}
    	else	if (res_1 == res_2) {
    		return 	  0;
    	}
    	else	if (res_1 > res_2) {
    		return	  1;
    	}
    	return 0;
    }

    Якобы вычисляет обратною польскою нотацию номер два

    lazy_8, 19 Апреля 2019

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

    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
    95. 95
    96. 96
    #include<math.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<ctype.h>
    #define  MAX 300
    
    struct stack {
    	char alpha;
    	struct stack *nxtPTR;
    
    };
    
    typedef struct stack  Stack;
    typedef  Stack *node;
    void  message(void);
    char out_print(char word[]);
    int precedence_power(int res_1, int  res_2);
    int pop(node *topPtr);
    void push_stack(node *topPTR, char value);
    int pop(node  *topPTR);
    char check_stack(node data);
    int isOperator(char c);
    int precedence(char data_1, char   data_2, int(intro_precedence_power)(int res_1, int  res_2));
    void  converting(char *in, char *out, node *PTR, char (checking_stack)(node), void (push)(node *topPTR, char value), int (pop)(node *fix), int (isOper)(char c), int (precedence_intro)(char data_1, char  data_2, int(intro_precedence_power)(int res_1, int  res_2)), int(intro_precedence_power)(int res_1, int  res_2));
    void  please_enter(void );
    
    int main(void) {
    	
    	char infix[MAX];
    	char postfix[MAX];
    	node topPTR = NULL;
    	
    	fgets(infix, sizeof(infix), stdin);
        int	m = strlen(infix);
    
    	infix[m] = ')';
    
    	memset(postfix, 0, MAX);
    	
    
      
    
    	converting( infix, postfix, &topPTR, check_stack, push_stack, pop, isOperator, precedence, precedence_power);
    	out_print(postfix);
    	
    	puts(" ");
    	
    return 0;
    }
    
    char out_print(char word[]) {
    
    if( word[0]  != '\0' ){
    	 	printf( "%c " ,  word[0]    ) ; 
    return    out_print(word + 1  )  ;
    }
    
    }
    
    void push_stack(node *topPTR, char value) {
    	node newPTR = malloc(sizeof(Stack));
    
    	if (newPTR != NULL) {
    
    		newPTR->alpha = value;
    		newPTR->nxtPTR = *topPTR;
    
    		*topPTR = newPTR;
    	}
    
    	else {
    
    		puts("error");
    
    	}
    }
    
    int pop(node *fix) {
    
    int value = (*fix)->alpha;
    
    	node temp = *fix;
    	*fix = (*fix)->nxtPTR;
    	free(temp);
    
    	return value;
    }
    
    char check_stack(node data) {
    	return data->alpha;
    }
    
    int isOperator(char c) {
    	return c == '/' || c == '*' || c == '-' || c == '+'  || c == '^'  ;
    }

    вычисляет обратною польскою нотацию номер раз

    lazy_8, 19 Апреля 2019

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

    +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
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    
    int main(void)
    {
      uint32_t a = 24804541;
      for(size_t i = 0; i < 5; i++)
      {
        for(size_t j = 0; j < 5; j++)
        {
          putchar( "01"[(a >> (i*5 + j)) & 1]);
        }
        putchar('\n');
      }
      return EXIT_SUCCESS;
    }

    https://ru.wikipedia.org/wiki/Параграф_86а_Уголовного_кодекса_Германии

    > В 1998 году суд Франкфурта-на-Майне своим решением запретил распространение компьютерных игр, в которых содержится какая-либо нацистская символика — прецедентом стала игра Wolfenstein 3D. Немецкие локализаторы вынуждены были заменять в играх нацистскую символику на другие символы, не попадающие под нарушение параграфа 86а Уголовного кодекса Германии.

    Предлагаю запретить число 24804541.

    j123123, 13 Апреля 2019

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

    +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
    #include <stdio.h>
    #include <stdlib.h>
    
    void myfree(void *ptr)
    {
      printf("%p\n", *(void **)ptr);
      free(*(void **)ptr);
      printf("freed!\n");
    }
    
    int main(void) {
      char *x __attribute__ (( cleanup (myfree)  )) = malloc(1);
      printf("%p\n", x);
      return 0;
    }

    https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

    cleanup (cleanup_function)

    The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.

    If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally.

    j123123, 09 Апреля 2019

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