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

    +139

    1. 1
    #define LIFMT(X) (long int) (X)

    Всё тот же квантовохимический пакет. Что характерно, от обычных кастов дальше никто не отказывается.

    dxd, 20 Марта 2015

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

    +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
    #include "mono-math.h"
    
    #ifndef HAVE_SIGNBIT
    
    int
    mono_signbit_float (float x)
    {
    	union { float f; int i; } u;
    
    	u.f = x;
    
    	return u.i < 0;
    }
    
    int
    mono_signbit_double (double x)
    {
    	union { double d; int i[2]; } u;
    
    	u.d = x;
    
    #if G_BYTE_ORDER == G_LITTLE_ENDIAN
    	return u.i [1] < 0;
    #else
    	return u.i [0] < 0;
    #endif
    }
    
    #endif

    Говно тут в том, что int далеко не везде будет 32 бит.
    https://github.com/mono/mono/blob/master/mono/utils/mono-math.c оттуда

    j123123, 19 Марта 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    /*
     * BIG UGLY WARNING! This is so damn ugly I wanna puke.  Unfortunately, some
     * macros that use ASN1_const_CTX still insist on writing in the input
     * stream.  ARGH! ARGH! ARGH! Let's get rid of this macro package. Please? --
     * Richard Levitte      
     */

    OpenSSL...

    bormand, 17 Марта 2015

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

    +137

    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
    #define poff    acurp + curp * (nSQs+2)        /*probs: offset*/
    long psum() {return  c(poff+ 1);}    long pmax()    {return c(poff+2);}
    long pn     (long n)                {return          c(poff+2+n);   }
    void setp   (long n, long x){set    (poff+2+n, x);} /*prob changes:*/ 
    void setmax         (long x){set    (poff+2,   x);} /*metasearching*/
    void setsum         (long x){set    (poff+1,   x);}
    long get2ndmax()    {long n= poff+2, x=pmax(), m=n,  s=0,end=n+nSQs;   
         do     {n++;}   while  (c(n) != x);  /*find 2nd-highest <=pmax*/     
         do     {m++;    if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
                 while      (s < x    && m < end);       return  s;}
    void addtoSQ(long i, long val) {long x;   /*increase prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  psum()+val;if (x > maxint) return;   /*has max normalizer*/
         setsum (x);    /*normalizer +*/ x =  pn(i)+val; setp(i, x); 
         if (x > pmax()) setmax (x);}   /*maximal SQprob has increased */    
    void subofSQ(long i, long val) {long x;   /*decrease prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  pn(i)-val; if (x < 0)      return;/*no neg probabilities!*/
         setsum (psum()- val);           setp(i,x);/*don't check if =0!*/   
         if (x + val  == pmax()) setmax (get2ndmax());} /*change of max*/
    void incSQ()        {long i= top();  addtoSQ(i,1);} /*top, not pop!*/
    void decSQ()        {long i= top(),  x,y,z; /*decrem prob of the SQ*/
         if  (i> nSQs   || i< 1) return;/*no such search Q number known*/
         x =  pn(i);     if     (x==0)   return;        /*SQ: already 0*/
         y  = psum();    z =     pmax();              
         if  (x == 1 &&  y    <= z+1)    stop    /*leave at least 2 SQs*/
         if  (x == z)    setmax         (get2ndmax());  /*change of max*/
         setp(i, x-1);   setsum (y-1);}                 /*normalizer -1*/
    long upSQ;          /*SQ probability:enumerator  +=  upSQ: increase*/
    void oldSQ()   {long a=pop()+ndecl,  n,i; if(a<0||a> oldp)stop/*bad*/
         n=old[a].size;  a=old[a].start;/*all SQs of old nondecl: +upSQ*/
         tncheck  n+=a;  for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q],     upSQ);}
    
    void setpat()       {long i= pop(); /*instantiate my search pattern*/
         if  (i<0 || i > patp)     stop /*no such search pattern exists*/
         set (acurp,i);}/*next SQ-search defined via new probabilities!*/
    void pupat()        {long    i  =    apatp;   /*push search pattern*/ 
         if  (i>maxpat)  stop    i++;    set(apatp,i);  /*not too many?*/
         cpabn  (poff+1, acurp + 1 + i *(2+ nSQs),       2 + nSQs,  
                                         acurp + 1,      aendpats);     }  
    void popat()        {long i= apatp;  if(i==0)   stop
         set(apatp,i-1); push(i); }                /*pop search pattern*/

    Полный исходник http://www.idsia.ch/~juergen/oopscode.c

    j123123, 17 Марта 2015

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

    +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
    void print_tetral(int i){
        switch(i){
        case 1:
            printf("      January                February                March\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 2:
            printf("       April                   May                    June\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 3:
            printf("        July                  August               September\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        case 4:
            printf("      October                 November               December\n");
            printf("Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su   Mo Tu We Th Fr Sa Su\n");
            break;
        default:
            break;
        }
    }

    alobanov, 16 Марта 2015

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

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int weeks_in_month(int month, int year){
        int weeks=1, first, i=0;  //i - числа месяца
        first = weekday(1, 1, 1, 1, 1, month, year);
        i += 8 - first;
        while(i <= days_in_month(month, year)){
            ++weeks;
            i += 7;
        }
        return weeks;
    }

    alobanov, 16 Марта 2015

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

    +132

    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
    void calendar(int year){
        int i, j, k, frst=1, week, length, day = 0;
        printf("                               ");
        if(year < 1000) printf(" ");
        printf("%d\n\n", year);
        int first[3];   // число начала недели (первая неделя - любой день недели, следющие - понедельник)
        for(i = 1; i <= 4; ++i){
            print_tetral(i);
            first[1] = weekday(1, 1, 1, 1, 1, i*3-2, year);
            first[2] = weekday(1, 1, 1, 1, 1, i*3-1, year);
            first[3] = weekday(1, 1, 1, 1, 1, i*3, year);
            length = max(weeks_in_month(i*3-2, year), \
                         weeks_in_month(i*3-1, year), \
                         weeks_in_month(i*3, year));
            for(week = 0; week < length; ++week){
                for(j = 1; j <= 3; ++j){
                    frst = first[j];
                    if(week > 0) frst = 1;
                    if(week == 0)
                        for(k = 1; k < first[j]; ++k)
                            printf("   ");
                    k = frst;
                    day = 0;
                    while(k <= 7 && day < days_in_month(i*3-3+j, year) && week < weeks_in_month(i*3-3+j, year)){
                        day = 7*week + k - first[j] + 1;
                        if(day > days_in_month(i*3-3+j, year)) break;
                        if(day < 10) printf(" %d ", day);
                        else if(day >= 10) printf("%d ", day);
                        ++k;
                    }
                    if(week == length - 1 || day >= days_in_month(i*3-3+j, year))
                        for(; k <= 7; ++k)
                            printf("   ");
                    printf("  ");
                }
                printf("\n");
            }
            printf("\n");
        }
    }

    Печатаем календарь.

    alobanov, 16 Марта 2015

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

    +130

    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
    int days_in_month(int month, int year){
        if(month == 2){
            if(is_leap_year(year)) return 29;
            else return 28;
        }
        if(month < 8){
            if(month % 2 == 1) return 31;
            else return 30;
        }
        if(month > 7){
            if(month % 2 == 1) return 30;
            else return 31;
        }
        return 0;
    }

    Количество дней в месяце. Моя первая кучка. Не судите строго ^_^

    alobanov, 16 Марта 2015

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

    +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
    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
    printf("Enter item code: ");                                        //Prompts user
    scanf ("%14s", codenew1);                                           //Read user input
    len = strlen(codenew1);                                             //Read each character into variable len
    
    while (len != strspn(codenew1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
    {
        printf ("Name contains non-alphabet characters. Try again!: "); //Prompts user to try again
        scanf ("%14s", codenew1);                                       //Reads user input
        len = strlen(codenew1);                                         //Read each character into variable len
    }                                                                   //Endwhile
    strncpy(codenew, codenew1,2);                                       //Copy the first two characters from the variable codenew1
    codenew[2] = 0;                                                     //Store first two characters into variavle codenew
    
    for ( j = 0; j < num_items; j++)                                    //Loop for num_items times
    {                                                                   //Beginning of for loop
        if (strcmp(array[j].code1, codenew) == 0)                       //If codenew is found in file
        {                                                               //Beginning of if statement
            price[i] = item_qty[i] * array[j].price1;                   //Calculating the price of an item
            printf("Price : %d", price[i]);                             //Prints price
            printf("\nEnter '%s' to confirm: ", array[j].itemname1);    //Confirming the item
            scanf("%19s", item_name1[i]);
            while (strcmp(item_name1[i], array[j].itemname1 )!=0)       //Looping until both item names are the same
            {                                                           //Begin while loop
                printf("Item name is not %s ,Try Again!: ", array[j].itemname1);    //Prompt user to try again
                scanf ("%19s", item_name1[i]);                              //Reads item name into an array
                len = strlen(item_name1[i]);                                //Reads each character into variable len
            }                                                               //End while loop
            len = strlen(item_name1[i]);                                    //Read each character into variable len
            while (len != strspn(item_name1[i], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))    //While len contains non alphabetic characters
            {                                                                       //Beginning while
                printf ("Name contains non-alphabet characters. Try again!: ");     //Prompts user to try again
                scanf ("%19s", item_name1[i]);                                      //Read user input
                len = strlen(item_name1[i]);                                        //Read each character into variable len
            }                                                                       //End while
            strncpy(item_name[i], item_name1[i], 20);                               //Copy the first two characters from the variable codenew1
            item_name[i][20] = 0;                                                   //Store first 20 characters in variable item_name[i]
            total_price+= price[i];                                     //Calculate total price
            break;                                                      //Terminates loop
        }                                                               //End of if statement
        else 
            if (strcmp(array[j].code1, codenew) != 0)                       //If codenew is found in file
            {
                printf("Invalid input! Try again.");
                goto Here;
            }
    }                                                           //End of for loop

    Бесценные комментарии!
    http://stackoverflow.com/questions/29045067/error-check-files

    myaut, 14 Марта 2015

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

    +127

    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
    #include <stdio.h>
    int main()
    {
    int i,g;
    char a[26];
    a[0]='a';
    a[1]='b';
    a[2]='c';
    a[3]='d';
    a[4]='e';
    a[5]='f';
    a[6]='g';
    a[7]='h';
    a[8]='i';
    a[9]='j';
    a[10]='k';
    a[11]='l';
    a[12]='m';
    a[13]='n';
    a[14]='o';
    a[15]='p';
    a[16]='q';
    a[17]='r';
    a[18]='s';
    a[19]='t';
    a[20]='u';
    a[21]='v';
    a[22]='w';
    a[23]='x';
    a[24]='y';
    a[25]='z';
    for(i=0;i<25;i++)
    {
    for(g=0;g<i+1;g++)
    {
    printf("%c",a[g]);
    }
    if(g!=25)
    printf("\n");
    
    }
    return 0;
    }

    К предыдущему коду.

    alexmir, 12 Марта 2015

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