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

    +143

    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
    void ** __attribute__((noinline)) findVoidSortMap(void ** list,void *key)
    {
        if (!list) return 0;
        if (!*list) return 0;
        unsigned int count= **(unsigned int**)list;
        char *p=(char*)*list;
        p+=4;
        Element *b=(Element *)p;
     
        long long skey=(long long)key;
     
        while (count>0) {
            void** kt=(void**)&b[count>>1];
            long long rkey=(long long)kt[0];
            if (skey==rkey) return (void**)&kt[1];
            if (skey>rkey) {b+=(count>>1)+1;count--;}
            count=count>>1;
        }
     
        return (void**)-1;
    }

    гуру осемблира на этом коде доказывал, что Эльбрус сосёт
    http://www.gamedev.ru/flame/forum/?id=196722&page=33#m481

    TarasB, 05 Января 2015

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

    +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
    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
    /*
         * Lack of time prevents me from writing this segment properly.
         * May Krishna have mercy on my soul.
         */
        static const uint32_t pal            = 720 * 576 * 2;
        static const uint32_t ntsc_composite = 720 * 507 * 2;
        static const uint32_t ntsc_sdi       = 720 * 480 * 2;
        uint16_t new_width = width, new_height = height;
    
        if (height == 0) {
            new_width = 1920;
            new_height = 1080;
        }
    
        if (format == PAL) {
            rv = pal;
            memset(out_payload, 0x3F, rv);
        }
        else if (format == NTSC) {
            if (source == SDI_VIDEO) {
                rv = ntsc_sdi;
                memset(out_payload, 0x3F, rv);
            }
            else {
                rv = ntsc_composite;
                memset(out_payload, 0x3F, rv);
            }
        }
        else {
            rv = new_width * new_height * 2;
            memset(out_payload, 0x3F, rv);
        }

    Вот что переизбыток мочи делает.

    codemonkey, 31 Декабря 2014

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

    +142

    1. 1
    return (guint)(((double)(((double)((SAMPLERATE_48KHZ)) / (((double)(fps_numerator) / (double)(fps_denominator)))))));

    Фу, блять.

    codemonkey, 29 Декабря 2014

    Комментарии (55)
  4. Си / Говнокод #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)
  5. Си / Говнокод #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)
  6. Си / Говнокод #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)
  7. Си / Говнокод #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)
  8. Си / Говнокод #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)
  9. Си / Говнокод #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)
  10. Си / Говнокод #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)