1. Лучший говнокод

    В номинации:
    За время:
  2. Куча / Говнокод #25859

    −103

    1. 1
    Я гниль.

    rHujlb, 20 Сентября 2019

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    switch (true)
    {
    
    }

    pillar_hunter, 11 Апреля 2019

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

    +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
    #include <stdio.h>
    #include <stdlib.h>
    
    void myfree(void *ptr)
    {
      printf("%p\n", *(void **)ptr);
      free(*(void **)ptr);
      printf("freed!\n");
    }
    
    int main(void) {
      char *x __attribute__ (( cleanup (myfree)  )) = malloc(1);
      printf("%p\n", x);
      return 0;
    }

    https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

    cleanup (cleanup_function)

    The cleanup attribute runs a function when the variable goes out of scope. This attribute can only be applied to auto function scope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter, a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.

    If -fexceptions is enabled, then cleanup_function is run during the stack unwinding that happens during the processing of the exception. Note that the cleanup attribute does not allow the exception to be caught, only to perform an action. It is undefined what happens if cleanup_function does not return normally.

    j123123, 09 Апреля 2019

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

    +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
    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
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    #include <inttypes.h>
    
    auto a(auto b) __attribute__ ((noinline));
    
    auto a(auto b)
    {
        return b*1.5;
    }
    
    double test1(double in)
    {
      return a(in);
    }
    
    uint64_t test2(uint64_t in)
    {
      return a(in);
    }
    
    
    /*
    https://godbolt.org/z/6ZQAnv
    
    auto a<double>(double):
            mulsd   xmm0, QWORD PTR .LC0[rip]
            ret
    test1(double):
            jmp     auto a<double>(double)
    auto a<unsigned long>(unsigned long):
            test    rdi, rdi
            js      .L5
            pxor    xmm0, xmm0
            cvtsi2sd        xmm0, rdi
            mulsd   xmm0, QWORD PTR .LC0[rip] # хули ты мне плавучего питуха в xmm0 возвращаешь?
            ret
    .L5:
            mov     rax, rdi
            and     edi, 1
            pxor    xmm0, xmm0
            shr     rax
            or      rax, rdi
            cvtsi2sd        xmm0, rax
            addsd   xmm0, xmm0
            mulsd   xmm0, QWORD PTR .LC0[rip]
            ret
    test2(unsigned long):
            sub     rsp, 8
            call    auto a<unsigned long>(unsigned long)
            movsd   xmm1, QWORD PTR .LC1[rip]
            comisd  xmm0, xmm1
            jnb     .L8
            cvttsd2si       rax, xmm0 # ну нахуй тут надо double в uint64_t конвертить
            add     rsp, 8 # почему это не делается в auto a<unsigned long>(unsigned long)
            ret
    .L8:
            subsd   xmm0, xmm1
            add     rsp, 8
            cvttsd2si       rax, xmm0
            btc     rax, 63
            ret
    .LC0:
            .long   0
            .long   1073217536
    .LC1:
            .long   0
            .long   1138753536
    
    */

    концепты-хуепты

    j123123, 23 Марта 2019

    Комментарии (28)
  6. Куча / Говнокод #24890

    0

    1. 1
    2. 2
    3. 3
    [...]
    After some configuration changes, I was able to add the 2000 ports by defining them out manually.
    [...]

    https://stackoverflow.com/questions/37992007/creating-ftp-service

    Потрудился наславу: создал 2К портов в конфигурации, вручную!

    Напомнило историю с МСДН, когда гейдев пожаловался на то, что сапер тормозит: он его создал из 5000 кнопок, которые он поставил на формочку в ВинФормс.

    Но самое говно-то не там, а в Кубернетисе, конечно.

    wvxvw, 10 Октября 2018

    Комментарии (28)
  7. Pascal / Говнокод #24826

    −3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    {$APPTYPE CONSOLE}
    Procedure G(p: pointer);
    Const
        Messages: array[false..true] of string = ('Не гниль', 'Гниль');
    Begin
        Writeln(Messages[p=nil])
    End;
    
    Begin
        G(nil)
    End.

    https://ideone.com/XWhPQf

    nu3gELL, 27 Сентября 2018

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

    0

    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
    #include<iostream>
    #include<fstream>
    #include<vector>
    using namespace std;
    string rec(const string str, char c){return str;} //syntax error : missing ';' before identifier 'rec', ')' before 'const',  ')', ';' before '{', 
                                                                                    //'str' : undeclared identifier, 'rec': identifier not found
    
    void cer(){}                                                            //'cer' : local function definitions are illegal
    
    main(){                                                                  //'main': identifier not found
    
    	string s, d="Math.cos",a;                  //missing '}' before identifier 's',  ';' before identifier 's', 's', 'd', 'a' : undeclared identifier
    	
            ifstream fin;
    	vector<string> mas; // 'std::vector' : 'string' is not a valid template type argument for parameter '_Ty', 'mas' : unknown size
                                                  //'std::vector' : no appropriate default constructor available
    
    fin.open(mDocWrite); //'void std::basic_ifstream<char,std::char_traits<char>>::open(const char *,std::ios_base::open_mode)' : 
                                            //cannot convert argument 1 from 'nsAutoPtr<nsHtml5Tokenizer>' to 'const wchar_t *'
                         //No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    
    //if (fin.is_open()) cout<<"1";else	cout<<"0";
    while(fin>>s)    //'s' : undeclared identifier, fatal error C1903: unable to recover from previous error(s); stopping compilation
    	{bool f=0;
    		for(int i=0; i<s.size(); ++i)
    			if (s[i]==d[0])
    				{
    					f=1;
    					for (int j=0; j<s.size()&&j<d.size(); ++j)
    						if (d[j]!=s[i+j]) f=0;
    					if (f)
    						{
    							a.clear();
    							for (int j=0; j<i; ++j)
    								a=a+s[j];
    							a=a+"0.5*";
    							for (int j=i; j<s.size(); ++j)
    								a=a+s[j];
    						}
    				}
    						if (f)	{mas.push_back("\n");mas.push_back(a);mas.push_back("\n");}
    			else mas.push_back(s);
    			s=rec(s,'0');
    	}
    	ofstream fout;
    fout.open(mDocWrite);
    for (int i=0; i<mas.size(); ++i) fout<<mas[i]<<"\t";
    }

    предполагалось, что код будет уменьшать cos угла в два раза, но при компиляции выдает ошибки, логику большинства которых не могу понять. Ошибки указал в коде. Подскажите, что не так.

    DrAli, 04 Сентября 2018

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

    +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
    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 <iostream>
    #include <type_traits>
    #include <utility>
    #include <array>
    
    template<size_t Size, typename T, typename FunctorType, size_t... idx>
    constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
                  map_impl(const std::array<T, Size> & arr, FunctorType && f, std::index_sequence<idx...>)
    {
        return std::array{ f(std::get<idx>(arr))... };
    }
    
    template<size_t Size, typename T, typename FunctorType>
    constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
                  map(const std::array<T, Size> & arr, FunctorType && f)
    {
        return map_impl(arr, f, std::make_index_sequence<Size>{});
    }
    
    struct MyFunctor {
        constexpr float operator()(int arg)
        {
            return static_cast<float>(arg * arg) / 2.0f;
        }
    };
    
    int main()
    {
        constexpr std::array arr{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    
        auto arrMappedFunctor = map(arr, MyFunctor{});
        auto arrMappedLambda = map(arr, [](int x) constexpr { return static_cast<float>(x * x) / 2.0f; });
    
        for (auto && x : arrMappedFunctor) {
            std::cout << x << ' ';
        }
        std::cout << std::endl;
        for (auto && x : arrMappedLambda ) {
            std::cout << x << ' ';
        }
        std::cout << std::endl;
        return 0;
    }

    0.5 2 4.5 8 12.5 18 24.5 32 40.5 50
    0.5 2 4.5 8 12.5 18 24.5 32 40.5 50


    Метушня выходит на новый уровень: полноценный map в compile-time. Поддерживает как ручные функторы с перегруженным operator(), так и constexpr-лямбды. При помощи небольшой модификации возможно реализовать поддержку кортежей с произвольными типами.

    gost, 18 Августа 2018

    Комментарии (28)
  10. Куча / Говнокод #24623

    0

    1. 1
    Ну как вы тут, потомки? Борманд еще живой?

    nihau, 14 Августа 2018

    Комментарии (28)
  11. Куча / Говнокод #24358

    0

    1. 1
    2. 2
    3. 3
    Кококо
    "Microsoft" купил "GitHub" 
    Кококо

    guestinxo, 04 Июня 2018

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