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

    +143

    1. 1
    sprintf(path, "/usr/local/something/something_else_%d_%d.uyvy%c", some_int, some_other_int, '\0');

    Мда-с.

    codemonkey, 28 Декабря 2014

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

    +141

    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
    date = j / 86400l;
    t = j - (date * 86400l);
    date += 731000ul;
    y = (4 * date - 1) / 146097;
    d = (4 * date - 1 - 146097 * y) / 4;
    date = (4 * d + 3) / 1461;
    d = (4 * d + 7 - 1461 * date) / 4;
    m = (5 * d - 3) / 153;
    d = (5 * d + 2 - 153 * m) / 5;
    y = 100 * y + date;
    if (m < 10) {
        m += 3;
    } else {
        m -= 9;
        y++;
    }

    Voodoo magic...

    bormand, 26 Декабря 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #ifndef STDC
    #  ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
    #    define const       /* note: need a more gentle solution here */
    #  endif
    #endif

    Совместимость

    Ccik, 22 Декабря 2014

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

    +140

    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
    HIMAGELIST ImageList_LoadImageV(PVOID ImageBase, PCWSTR a[], int level)
    {
    	PIMAGE_RESOURCE_DATA_ENTRY pirde;
    	PBITMAPINFOHEADER pbih;
    	DWORD cx, cy, cb, n, ofs;
    	if (
    		0 <= LdrFindResource_U(ImageBase, a, level, &pirde) && 
    		0 <= LdrAccessResource(ImageBase, pirde, (void**)&pbih, &cb) &&
    		cb > sizeof(BITMAPINFOHEADER) &&
    		pbih->biSize >= sizeof(BITMAPINFOHEADER) &&
    		(cx = pbih->biWidth) <= (cy = pbih->biHeight) &&
    		!(cy % cx) &&
    		pbih->biBitCount == 32 &&
    		(ofs = pbih->biSize) + (cx * cy << 2) == cb
    		)
    	{
    		n = cy / cx, cb = cx * cx << 2;
    
    		if (HIMAGELIST himl = ImageList_Create(cx, cy, ILC_COLOR32, n, 0))
    		{
    			BITMAPINFO bi = { {sizeof(BITMAPINFOHEADER), cx, cx, 1, 32 } };
    
    			if (HDC hdc = GetDC(0))
    			{
    				if (HBITMAP hbmp = CreateCompatibleBitmap(hdc, cx, cx))
    				{
    					do ; while (
    						SetDIBits(hdc, hbmp, 0, cx, RtlOffsetToPointer(pbih, ofs), &bi, DIB_RGB_COLORS) &&
    						0 <= ImageList_Add(himl, hbmp, 0) &&
    						(ofs += cb, --n)
    						);
    
    					DeleteObject(hbmp);
    				}
    
    				ReleaseDC(0, hdc);
    			}
    
    			if (!n) return himl;
    
    			ImageList_Destroy(himl);
    		}
    	}
    
    	return 0;
    }

    zhukas, 14 Декабря 2014

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

    +135

    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
    int log2_floor (unsigned x)
    {
        #define NIMHTNOE0WNM(n) (((~(x>>n)+1)>>n)&n)
     
        int res, n;
     
        n = NIMHTNOE0WNM(16); res  = n; x >>= n;
        n = NIMHTNOE0WNM( 8); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 4); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 2); res |= n; x >>= n;
        n = NIMHTNOE0WNM( 1); res |= n;
        return res;
    }

    Кто-то Воррена перечитал.

    codemonkey, 11 Декабря 2014

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

    +138

    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
    int fermat (void)
    {
      const int MAX = 1000;
      int a=1,b=1,c=1;
      while (1) {
        if (((a*a*a) == ((b*b*b)+(c*c*c)))) return 1;
        a++;
        if (a>MAX) {
          a=1;
          b++;
        }
        if (b>MAX) {
          b=1;
          c++;
        }      
        if (c>MAX) {
          c=1;
        }
      }
      return 0;
    }
    
    #include <stdio.h>
    
    int main (void)
    {
      if (fermat()) {
        printf ("Fermat's Last Theorem has been disproved.\n");
      } else {
        printf ("Fermat's Last Theorem has not been disproved.\n");
      }
      return 0;
    }

    Fermat's Last Theorem has been disproved
    http://blog.regehr.org/archives/140

    Если уже было черкните мне на /dev/null@localhost, удалю

    Elvenfighter, 11 Декабря 2014

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

    +136

    1. 1
    2. 2
    /* To the unenlightened: This sets the 20 MSBs to 0 for sanity's sake. */
    return four_bytes_to_uint32(four_byte_array) & ~(~0 << 12);

    Так приказали K&R.

    codemonkey, 10 Декабря 2014

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

    +139

    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
    char* xml_compose_simple_response(char* response, int code, char* description, char* additional_data)
    {
    	size_t resp_length = 0;
    	char* buff = NULL;
    
    	resp_length += strlen(RESPONSE_HEADER_PREFIX);
    	resp_length += strlen(session_type);
    	resp_length += strlen(transaction_id);
    	resp_length += strlen(response) + strlen(EMPTY_TAG);
    	if(NULL != additional_data)
    	{
    		resp_length += strlen(additional_data);
    	}
    	resp_length += strlen(description) + strlen(RESULT_INT) + sizeof(int) * 8;
    	resp_length += strlen(RESPONSE_HEADER_SUFFIX);
    
    	resp_length += 1;
    
    	if(NULL != (buff = malloc(resp_length)))
    	{
    		buff[0] = '\0';
    
    		sprintf(buff, RESPONSE_HEADER_PREFIX""EMPTY_TAG, session_type, transaction_id, response);
    
    		if (additional_data != NULL)
    		{
    			char tmp_desc[_2K];
    			sprintf(tmp_desc, description, additional_data);
    
    			sprintf(&buff[strlen(buff)], RESULT_INT, code, tmp_desc);
    		}
    		else
    		{
    			sprintf(&buff[strlen(buff)], RESULT_INT, code, description);
    		}
    		strcat(buff, RESPONSE_HEADER_SUFFIX);
    	}
    	else
    	{
    		mng_report_memory_failure_location_and_exit();
    	}
    	return buff;
    }

    XML вручную собирай @ на кавычкай падай. Никакого АПИ, только хардкор.

    codemonkey, 07 Декабря 2014

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

    +135

    1. 1
    return (true == is_break) ? resource : NULL;

    Вонъ изъ профессiи!

    codemonkey, 07 Декабря 2014

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

    +131

    1. 1
    2. 2
    // bg_pmove.c -- both games player movement code
    // takes a playerstate and a usercmd as input and returns a modifed playerstate

    Дальше идут 11 тысяч строк нечитаемого говна. Это вообще нормально?!

    gost, 03 Декабря 2014

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