1. C++ / Говнокод #3562

    +167

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    re:    data=new unsigned char[sz+1];
    #ifdef SAFEMEM
        if(!data){ SAFEMEM Sleep(1); goto re;}
    #endif
    
    Источник: http://rsdn.ru/forum/cpp.applied/3852182.aspx

    alexander-berezin, 24 Июня 2010

    Комментарии (25)
  2. C++ / Говнокод #3555

    +148

    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
    struct table1
    
    {
    
    	char name_of_function[3];
    
    	char name_of_variable[3];
    
    	char values[50];
    
    };
    
    struct table2
    
    {
    
    	char name_of_function[3];
    
    	char name_of_variable[3];
    
    	char values[50];
    
    };
    
    ///
    
    table1 potential[10];
    table2 returned[10];
    
    ///
    
     if(strcmp(s,returned[m].name_of_function)==0)
    						 {
    							while((strcmp(potential[mm].name_of_function,returned[m].name_of_function)!=0)&&mm<10){mm++; mmm=mm;}
    							if((strcmp(potential[mmm].name_of_function,returned[m].name_of_function)==0)&&mm<10)
    							{	
    								while(strcmp(potential[mmm].name_of_function,returned[m].name_of_function)==0){mmm++;}
    								mmm--;
    								while((mm<=mmm)&&bo==false)
    								{
    									if(strcmp(potential[mmm].name_of_variable,returned[m].name_of_variable)==0)
    									{
    										strcpy(returned[m].values,potential[mmm].values);
    										bo=true;
    									}
    									mmm--;
    								}
    								if(bo==false)
    								{
    									strcpy(returned[m].values,"ax\0");
    								}
    							}							
    						 }
    ///

    Лишь небольшой кусок из курсового проекта.

    Mifodix, 24 Июня 2010

    Комментарии (19)
  3. C++ / Говнокод #3553

    +174

    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
    signed ToBool(signed b){unsigned t=b;return ( ((t<<0)>>31)  |  ((t<<1) >>31)  |  ((t<<2) >>31)  |  ((t<<3) >>31)  |  ((t<<4) >>31) | ((t<<5) >>31) | ((t<<6) >>31) | ((t<<7) >>31) | ((t<<8) >>31) | ((t<<9) >>31) | ((t<<10) >>31) | ((t<<11) >>31) | ((t<<12) >>31) | ((t<<13) >>31) | ((t<<14) >>31) | ((t<<15) >>31) | ((t<<16) >>31) | ((t<<17) >>31) | ((t<<18) >>31) | ((t<<19) >>31) | ((t<<20) >>31) | ((t<<21) >>31) | ((t<<22) >>31) | ((t<<23) >>31) | ((t<<24) >>31) | ((t<<25) >>31) | ((t<<26) >>31) | ((t<<27) >>31) | ((t<<28) >>31) | ((t<<29) >>31) | ((t<<30) >>31) | ((t<<31) >>31) );};
    signed NotBool(signed b){/*signed b=ToBool(b);*/unsigned t=(~b)<<31;return t>>31;};
    signed isZero(signed a){return NotBool(ToBool(a));};
    signed isNotZero(signed a){return NotBool(isZero(a));};
    signed isSign(signed a){unsigned t=a;return (t>>31);};signed isNotSign(signed a){return NotBool(isSign(a));};
    signed isEqual(signed a,signed b){	return isZero(a-b);};
    signed isNotEqual(signed a,signed b){return NotBool(isEqual(a,b));};
    signed isLess(signed a,signed b){return isSign(a-b);};
    signed isEqualMore(signed a,signed b){return NotBool(isLess(a,b));};
    signed isEqualLess(signed a,signed b){return isEqual(a,b)|isLess(a,b);};
    signed isMore(signed a,signed b){return NotBool(isEqualLess(a,b));};
    signed Equal(signed a,signed b,signed success,signed fail){signed t=isEqual(a,b);return (success*t)+(fail*NotBool(t));};
    signed NotEqual(signed a,signed b,signed success,signed fail){signed t=NotBool(isEqual(a,b));return (success*t)+(fail*NotBool(t));};
    signed Less(signed a,signed b,signed success,signed fail){signed t=isLess(a,b);return (success*t)+(fail*NotBool(t));};
    signed More(signed a,signed b,signed success,signed fail){signed t=isMore(a,b);return (success*t)+(fail*NotBool(t));};
    signed EqualLess(signed a,signed b,signed success,signed fail){signed t=isEqualLess(a,b);return (success*t)+(fail*NotBool(t));};
    signed EqualMore(signed a,signed b,signed success,signed fail){signed t=isEqualMore(a,b);return (success*t)+(fail*NotBool(t));};

    Вот такое форматирование... Хотя функции какие-то сомнительные...

    Говногость, 23 Июня 2010

    Комментарии (33)
  4. C++ / Говнокод #3552

    +170

    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
    //Файл teamWorkFile.h:
    static int teamWork(int e)
    {
    #if N==0
    	return 0;
    #elif N==1
    	return Work52(e+1);
    #elif
    	return WorkN(N);
    #endif
    };
    
    //Файл teamWork.h:
    //...
    #define MaxProc 6
    typedef int (*ProcTypeTeamWork)(int e);
    ProcTypeTeamWork Proc[MaxProc]; 
    #define N 0
    #define teamWork ProcName0
    #include "teamWorkFile.h"
    #undef teamWork
    #undef N
    #define N 1
    #define teamWork ProcName1
    #include "teamWorkFile.h"
    #undef teamWork
    #undef N
    int InitMultiProc()
    {
    	Proc[0]=ProcName0;
    	Proc[1]=ProcName1;
    	Proc[2]=ProcName1;
    	Proc[4]=ProcName0;
    	Proc[5]=ProcName1;
    	return 0;
    };
    
    //Файл teamWorkLib.cpp:
    #include "teamWork.h"
    //...
    InitMultiProc();
    ProcTypeTeamWork SuperProc=Proc[5];
    //Дальше в этом файле вызовы в стиле Proc[i](e);, SuperProc(255); и тд...

    Удивительный код состоит из 3х файлов(teamWorkLib.cpp, teamWork.h, teamWorkFile.h), но он того стоит.

    Говногость, 23 Июня 2010

    Комментарии (39)
  5. C++ / Говнокод #3551

    +167

    1. 1
    2. 2
    3. 3
    bool dicLoaded_ = false;
    ....
    dicLoaded_ = dicLoaded_?false:true;

    Еще один перл из кандидатских заданий. Любителям тернарных операторов посвящается.

    Lexey, 23 Июня 2010

    Комментарии (7)
  6. C++ / Говнокод #3550

    +167

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #define ItemType char
    #define SecondItemType unsigned
    class Doubler
    {
    	ItemType _i1_;
    	SecondItemType _i2_;
    	//...
    	//Дальше идёт много функций класса, использующие ItemType и SecondItemType.
    	//...
    };

    Говногость, 23 Июня 2010

    Комментарии (1)
  7. C++ / Говнокод #3549

    +159

    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
    class ControlerSingleton
    {
    private:
    	static int ControlCode;
    	static bool disaPear;
    	static int ArraySize;
    	//...
    	void Constructor()
    	{
    		//...
    		ArraySize=sizeof(masi)/sizeof(masi[0]);
    		disaPear=Pear();
    		threadRAII.Wait();
    		ControlCode=threadRAII.result();
    		//...
    	};
    	static int construct=Constructor();
    public:
    	const bool Pear()
    	{
    	//...
    };

    Своеобразный "конструктор" в классе синглтона.

    Говногость, 23 Июня 2010

    Комментарии (112)
  8. C++ / Говнокод #3548

    +163

    1. 1
    smart_ptr<const AbstractElanos> pointy;struct Intializer{Intializer(void){pointy=new Elanos;};}initer;

    Согласно проектного решения

    smart_ptr<const AbstractElanos> pointy=new Elanos;

    писать нельзя. Конструктор из поинтера не определён.
    Ну а народ любит размещать данные глобально и сразу инициализировать. Последствия весьма наглядны.

    Говногость, 23 Июня 2010

    Комментарии (21)
  9. C++ / Говнокод #3542

    +160

    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
    //
    Fraction Fraction::operator +(Fraction &ob)
    {
    	int f;int d; int c; int k; int l; int z;
    	char*p; char*x;
    	p=new char; x=new char;
    	Fraction tempOb;
    	if(strcmp(znam, ob.znam)==0)
    	{
    		f=atoi(tempOb.chisl);
    		d=atoi(ob.chisl);
    		c=atoi(chisl);
    		f=d+c;
    		k=atoi(tempOb.znam);
    		l=atoi(znam);
    		k=l;
    		p=itoa(f,p,10);
    		x=itoa(k,x,10);
    		strcpy(tempOb.chisl,p);
    		strcpy(tempOb.znam,x);
    	}
    	else
    	{
    		f=atoi(tempOb.chisl);
    		d=atoi(ob.chisl);
    		c=atoi(chisl);
    		k=atoi(ob.znam);
    		l=atoi(znam);
    		f=c*k+d*l;
    		z=atoi(tempOb.znam);
    		z=l*k;
    		p=itoa(f,p,10);
    		x=itoa(z,x,10);
    		strcpy(tempOb.chisl,p);
    		strcpy(tempOb.znam,x);
    	}
    	tempOb.operator ~();
    	return tempOb;
    }
    //

    Нашел баг с переполнением, если вводишь слишком большие числа. Пытаюсь сделать через char. Работает. Но такие фрагменты кода убивают. Реально сделать легче, а еще лучше если сразу через int?

    ForEveR, 23 Июня 2010

    Комментарии (15)
  10. C++ / Говнокод #3539

    +164

    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
    list::list(FILE*f,FILE*f1){
        first=(starosta*)new student;
        rea=first;
        int i=0,j;
        for(j=0;j<5;j++){
            if (i) {
                rea->next=(starosta*)new student;
                rea=rea->next;
            }
            i=1;
            fscanf(f,"%d",&(rea->num));
            fscanf(f,"%s",rea->fam);
            fscanf(f,"%d",&(rea->stip));
            rea->flag=0;
        }
        cur=(starosta*)rea;
        for(j=0;j<3;j++){
            cur->next=new starosta;
            cur=(starosta*)cur->next;
            cur->flag=1;
            fscanf(f1,"%d",&(cur->num));
            fscanf(f1,"%s",cur->fam);
            fscanf(f1,"%d",&(cur->stip));
            fscanf(f1,"%d",&(cur->kolvo));
            cur->next=NULL;
        }
    }

    классный конструктор... тут много приколов

    tony, 22 Июня 2010

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