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

    +133.6

    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
    char *errdesc;
    
    [...]
    
                switch errno
                {
                    case EACCES: errdesc="For Unix domain sockets, which are identified by pathname: Write permission is denied on the socket file, or search permission is denied for one of the directories in the path prefix. (See also path_resolution(2).) " ;break;
                    case EPERM: errdesc="The user tried to connect to a broadcast address without having the socket broadcast flag enabled or the connection request failed because of a local firewall rule. ";break;
                    case EADDRINUSE: errdesc="Local address is already in use. ";break;
                    case EAFNOSUPPORT: errdesc="The passed address didn't have the correct address family in its sa_family field. ";break;
                    case EAGAIN: errdesc="No more free local ports or insufficient entries in the routing cache. For PF_INET see the net.ipv4.ip_local_port_range sysctl in ip(7) on how to increase the number of local ports. ";break;
                    case EALREADY: errdesc="The socket is non-blocking and a previous connection attempt has not yet been completed. ";break;
                    case EBADF: errdesc="The file descriptor is not a valid index in the descriptor table. ";break;
                    case ECONNREFUSED: errdesc="No one listening on the remote address. ";break;
                    case EFAULT: errdesc="The socket structure address is outside the user's address space. ";break;
                    case EINPROGRESS: errdesc="The socket is non-blocking and the connection cannot be completed immediately. It is possible to select(2) or poll(2) for completion by selecting the socket for writing. After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully (SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure). ";break;
                    case EINTR: errdesc="The system call was interrupted by a signal that was caught. ";break;
                    case EISCONN: errdesc="The socket is already connected. ";break;
                    case ENETUNREACH: errdesc="Network is unreachable. ";break;
                    case ENOTSOCK: errdesc="The file descriptor is not associated with a socket. ";break;
                    case ETIMEDOUT: errdesc="Timeout while attempting connection. The server may be too busy to accept new connections. Note that for IP sockets the timeout may be very long when syncookies are enabled on the server.";break;
                    case EADDRNOTAVAIL: errdesc="EADDRNOTAVAIL";break;
                    case EPROTOTYPE: errdesc="EPROTOTYPE";break;
                    case EINVAL: errdesc="Invalid argument passed.";break;
                    case ENOMEM: errdesc="Could not allocate memory for recvmsg().";break;
                    case ENOTCONN: errdesc="The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).";break;
                    default: errdesc="Unknown error";break;
                }

    Мдя, просматривать код писанный мной же, когда я ещё только-только начинал писать на Си стыдновато. :)

    xaionaro, 28 Февраля 2010

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

    +99.4

    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
    #include <iostream>
    
    int *sfirst_function(void);
    int *isecond_function(void);
    
    int * sfirst_function(void)
    {
    	int ilocal_to_first=11;
    	return &ilocal_to_first; // Возвращаем указатель на переменную, размещенную в стеке
    } 
    
    int *isecond_function(void)
    {
    	int ilocal_to_second=44;
    	return &ilocal_to_second; // ну и тут
    }
    void main()
    {
    	int *pi=sfirst_function();
    	printf("First Function = %d\n",*pi);
    	int *si= isecond_function();
    	printf("Second Function = %d\n",*si);
    }

    Найдено на античате, в топике "помощь с лабораторными"
    В этом конкретном примере, конечно, допустим возврат адреса локальной переменной, а вот в более крупном проекте автор столкнулся бы с нефиговой проблемой =)

    RankoR, 18 Февраля 2010

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

    +135.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
    inline void clearbufshort (void *buff, unsigned int count, WORD clear)
    {
            if (!count)
                    return;
            SWORD *b2 = (SWORD *)buff;
            if ((int)b2 & 2)
            {
                    *b2++ = clear;
                    if (--count == 0)
                            return;
            }
            do
            {
                    *b2++ = clear;
            } while (--count);
    }

    Наткнулся на такой вот шедевр в коде ZDaemon. Это аналог memset, только заполняет не байтами, а словами.

    Кстати, там же рядом есть функция, запполняющая двойными словами:

    inline void clearbuf (void *buff, int count, SDWORD clear)
    {
    SDWORD *b2 = (SDWORD *)buff;
    while (count--)
    *b2++ = clear;
    }

    Arseniy, 13 Февраля 2010

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

    +137.6

    1. 1
    w = (GtkWidget*)(*((int*)(lw->data)));

    Объект для медитаций

    mutanabbi, 13 Февраля 2010

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

    +137.5

    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
    void TWindowTID::SetStyle(GtkWidget* widget, const char *form, gint Red_, gint Green_, gint Blue_)
    {
        struct _GtkStyle *style;
        GdkColor bg;
        style=gtk_style_new();
        bg.red = Red_;
        bg.blue = Blue_;
        bg.green = Green_;
        if (form=="TEXT")
        {
            style->fg[GTK_STATE_NORMAL]=bg; //TEXT
        }
        else
            if (form=="BORDER")
            {
                style->base[GTK_STATE_NORMAL]=bg; //BORDER
            }
            else
                if (form=="ALL")
                {
                    style->bg[GTK_STATE_NORMAL]=bg;
                    style->base[GTK_STATE_NORMAL]=bg; //BORDER
                    style->fg[GTK_STATE_NORMAL]=bg; //TEXT
                }
                else
                    if (form=="button")
                    {
                        style->bg[GTK_STATE_PRELIGHT]=bg;
                        style->base[GTK_STATE_PRELIGHT]=bg; //BORDER
                        style->bg[GTK_STATE_SELECTED]=bg;
                        style->base[GTK_STATE_SELECTED]=bg; //BORDER
                    }
                    else
                    {
                        style->bg[GTK_STATE_NORMAL]=bg;
                    }
        style->font = gdk_font_load("-adobe-helvetica-*-r-*-*-12-*-*-*-*-*-*-*");
        if ((GtkWidget *)widget!=NULL) gtk_widget_set_style((GtkWidget *)widget, style);
    }

    Сравнение строк умиляет

    mutanabbi, 12 Февраля 2010

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

    +96.5

    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
    ......
                     int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0,a8=0,a9=0,a10=0;
                     for (int i=0;i<arl->Count;i++)
                     {
                        if(arl[i]<0.1)
                        {
                            a1++;
                        }
                        if(arl[i]<0.2&&arl[i]>0.1)
                        {
                            a2++;
                        }
                        if(arl[i]<0.3&&arl[i]>0.2)
                        {
                            a3++;
                        }
                        if(arl[i]<0.4&&arl[i]>0.3)
                        {
                            a4++;
                        }
                        if(arl[i]<0.5&&arl[i]>0.4)
                        {
                            a5++;
                        }
                        if(arl[i]<0.6&&arl[i]>0.5)
                        {
                            a6++;
                        }
                        if(arl[i]<0.7&&arl[i]>0.6)
                        {
                            a7++;
                        }
                        if(arl[i]<0.8&&arl[i]>0.7)
                        {
                            a8++;
                        }
                        if(arl[i]<0.9&&arl[i]>0.8)
                        {
                            a9++;
                        }
                        if(arl[i]<1&&arl[i]>0.9)
                        {
                            a10++;
                        }
                     }
    .....

    определение количества элементов в каждом диапазоне. Было написано быстро и влоб, т.к ничего красивее придумать не смог, да и времени не было.

    KoirN, 11 Февраля 2010

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

    +136

    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
    #define alias long
    #define int b
    #define cat 2
    alias int=cat;
    #undef int
    
    int a$(int b)
    {
      return 1;
    }
    
    main()
    {
      return a$(b)+1;
    }

    Здесь нет С++, зато есть... bash!
    На что спорим, что код возврата программы будет 1?

    nil, 05 Февраля 2010

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

    +144.8

    1. 1
    void updateEach(void *ptr, void *unused)

    chipmunk update method
    chipmunk - физический движок (типа под iPhone) на сях. Прелесть, правда?

    FIZZER, 04 Февраля 2010

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

    +138.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
    sprintf(cmd, "%supd_downloader -p upd_downloader\\bin %s %s -a %s", 
    #if defined(__unix__)
    	"./",
    #else
    	"",
    #endif
    	arg1, 
    	option->arg2 ? arg2 : "", 
    #if defined(__i386__) || defined(_M_X86)
    	"i686"
    #else
    	"x86_64"
    #endif
    );
    res = run_command(cmd);

    Обнаружил в коде. Типа портируемый код =) Да еще и sprintf() ...

    del, 02 Февраля 2010

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

    +134.8

    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
    #include "stdafx.h"
    #include "conio.h"
    #include "time.h"
    #include "stdlib.h"
    #include "windows.h"
    #include <iostream>
    
    
    using namespace std;
    void go()
    { int m[10],maxi,mini,max,min,temp;
    srand(time(NULL));
    for(int i=0;i<10;i++)
    m[i]=rand()%30;
    max=0;
    for(int i=0;i<10;i++)
    {if(m[i]>max) { max=m[i]; maxi=i;};
    }
    
    min=max;
    for(int i=0;i<10;i++)
    {if(m[i]<min) {min=m[i]; mini=i;};
    
    }
    for(int i=0;i<10;i++)
    cout<<m[i]<<endl;
    
    m[maxi],m[mini]=m[mini],m[maxi];
    temp=m[maxi];
    m[maxi]=m[mini];
    m[mini]=temp;
    
    
    cout<<"============"<<endl;
    for(int i=0;i<10;i++)
    cout<<m[i]<<endl;
    
    
    cout<<"alala=="<<max<<endl;
    cout<<"ololo=="<<min<<endl;
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    go();
    
    getch();
    
    
    	return 0;
    }

    хе-хе, друг написал , меняет макс и мин элементы местами)

    Bor1k, 02 Февраля 2010

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