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

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    #include <iostream>
    using namespace std;
    
    int main () {
      for( struct {int i; long i2;} x = {1, 1};
           x.i2 <= 100;
           x.i++, x.i2 = x.i * x.i ) {
        cout << x.i2 << endl;
      }
      return 0;
    }

    Поскольку реального ГК нет, добавлю синтетического.
    NB: Под MSVC такое не пройдет. g++ - ok: http://codepad.org/JesKsnMQ

    http://jia3ep.blogspot.com/2010/07/struct-in-for-loop.html

    Aleskey, 04 Июля 2011

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

    +166

    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
    // say this is some existing structure. And we want to use
    // a list. We can tell it that the next pointer
    // is apple::next.
    struct apple {
        int data;
        apple * next;
    };
    
    // simple example of a minimal intrusive list. Could specify the
    // member pointer as template argument too, if we wanted:
    // template<typename E, E *E::*next_ptr>
    template<typename E>
    struct List {
        List(E *E::*next_ptr):head(0), next_ptr(next_ptr) { }
    
        void add(E &e) {
            // access its next pointer by the member pointer
            e.*next_ptr = head;
            head = &e;
        }
    
        E * head;
        E *E::*next_ptr;
    };
    
    int main() {
        List<apple> lst(&apple::next);
    
        apple a;
        lst.add(a);
    }

    c++ страшный язык :) (часть вторая)

    C++: Pointer to class data member: http://stackoverflow.com/questions/670734/c-pointer-to-class-data-member

    Такие конструкции "E *E::*next_ptr;" без подготовки не осилить.

    Aleskey, 02 Июля 2011

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

    +147

    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
    try
    {
        // A lot of code
    }
    catch (Exception &exception)
    {
        Application->ShowException(&exception);
    }
    catch (...)
    {
        try
        {
           throw Exception("");
        }
        catch (Exception &exception)
        {
            Application->ShowException(&exception);
        }
    }

    :) Обработка исключений

    egoroff, 01 Июля 2011

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

    +163

    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 <stdio.h>
    
    const int (&getArray())[10] {
      static int tmp[10] = {1,2,3,4,5,6,7,8,9,10};
      return tmp;
    }
    
    void foo(const int (&refArr)[10])
    {
      size_t size = sizeof(refArr); // returns 10*sizeof(int)
      printf ("Array size: %d\r\n", size);
    }
    
    
    int main() {
      foo(getArray());
    
      printf ("%d", getArray()[0]);
      for (size_t i=1; i<sizeof(getArray())/sizeof(getArray()[0]); ++i)
        printf (",%d", getArray()[i]);
        
      return 0;
    }

    http://codepad.org/rPl6b7IS

    c++ страшный язык :)
    Извращения на тему: http://heifner.blogspot.com/2005/06/c-reference-to-array.html

    Aleskey, 30 Июня 2011

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

    +181

    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
    #include "iostream"
    using namespace std;
    
    enum {MaxFucktorial=13};
    static int fucks[MaxFucktorial+1];
    
    template<const int ValuePosition, const int Value>
    struct initFuckedValue
    {
    	enum {CurrentValue=Value*ValuePosition};
    	static void fuckUp(void)
    	{
    		fucks[ValuePosition]=CurrentValue;
    		initFuckedValue<ValuePosition+1, CurrentValue>::fuckUp();
    	};
    };
    template<const int Value>
    struct initFuckedValue<MaxFucktorial, Value>
    {
    	static void fuckUp(void){};
    };
    void InitFucks(void)
    {
    	fucks[0]=1;
    	initFuckedValue<1,1>::fuckUp();
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	cout<<"Введите аргумент факториала: "<<endl;
    	InitFucks();
    	int fuckArg=0;
    	cin>>fuckArg;
    	cout<<"Начинаем считать факториал..."<<endl
    	<<"Подсчёт факториала успешно завершён. ОК."<<endl
    	<<"Результат: "<<fucks[fuckArg]<<endl;
    	cin>>fuckArg;
    	return 0;
    }

    Решил запостить всё. Жемчужена.

    Мой знакомый, молодой преподаватель-аспирант из института пришёл однажды расстроенный. Спрашиваю у него: "Что случилось?"
    -- "Один мой первокурсник, когда я дал ему задание посчитать факториал через рекурсию принёс мне какую-то непонятную компилирующуюся галиматью. И считает она уж слишком быстро... Это какая-то программа обманка. Вообщем я ему поставил 2."

    Да, это лаба. ^_^

    Говногость, 28 Июня 2011

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

    +147

    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
    int __fastcall TForm1::iscomm(AnsiString str)
    {
    int i=1;
    while (str[i]==' ')
     i++;
    if (str[i]=='#')
     {
      return 1;
     }
    else
     {
      return 0;
     };
    };

    yasosiska, 27 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    cout<<"enterX"<<endl;
         cin >>x;
    x = 0.125;

    yasosiska, 27 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    uint32_t getuint32(char *p){
      return (*p<<24)|(*(p+1)<<16)|(*(p+2)<<8)|(*(p+3));
    }

    yasosiska, 27 Июня 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if(dOper1p->Caption == "-0")
       dOper1p->Caption = "+0";
     if(dOper2p->Caption == "-0")
       dOper2p->Caption = "+0";
    
     if(dOper1m->Caption == "-0.0")
       dOper1m->Caption = "+0.0";
     if(dOper2m->Caption == "-0.0")
       dOper2m->Caption = "+0.0";

    yasosiska, 27 Июня 2011

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

    +179

    1. 1
    2. 2
    public:
      void* getThis(void){return this;};;;;

    Говногость, 26 Июня 2011

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