1. Список говнокодов пользователя myaut

    Всего: 17

  2. C++ / Говнокод #21323

    −22

    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
    template< class T >
    T* addressof(T& arg) 
    {
        return reinterpret_cast<T*>(
                   &const_cast<char&>(
                      reinterpret_cast<const volatile char&>(arg)));
    }
    ...
    
     
    template<class T>
    struct Ptr {
    ...
        T** operator&() { return &data; }
    };
    
    int main() {
        Ptr<int> p(new int(42));
        f(&p);                 // calls int** overload
        f(std::addressof(p));  // calls Ptr<int>* overload, (= this)
    }

    Obtains the actual address of the object or function arg, even in presence of overloaded operator&
    http://en.cppreference.com/w/cpp/memory/addressof

    WTF?

    myaut, 04 Октября 2016

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

    +10

    1. 1
    http://i.imgur.com/g5MswBc.png

    Emotive programming in XCode

    myaut, 22 Июня 2016

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

    +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
    #include <iostream>
    
    namespace __hidden__ {
      struct print {
        bool space;
        print() : space(false) {}
        ~print() { std::cout << std::endl; }
    
        template <typename T>
        print &operator , (const T &t) {
          if (space) std::cout << ' ';
          else space = true;
          std::cout << t;
          return *this;
        }
      };
    }
    
    #define print __hidden__::print(),
    
    int main() {
      int a = 1, b = 2;
      print "this is a test";
      print "the sum of", a, "and", b, "is", a + b;
      return 0;
    }

    Отсюда: [color=violet]http://madebyevan.com/obscure-cpp-features/[/color]

    myaut, 13 Мая 2016

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

    +57

    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
    #include <iostream>
    #include <stdexcept>
    
    template<std::size_t N>
    static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
      return 
        (i + 2 + (last ? 0 : 1) >= N) 
            ? throw std::logic_error("Too short date string") :
        (!last && s[i + 2] != ':') 
            ? throw std::logic_error("Cannot find delimiter") :
        (s[i] < '0' || s[i] > '9' ||  s[i + 1] < '0' || s[i + 1] > '9') 
            ? throw std::logic_error("Not a number") :
        ((s[i] - '0') * 10 + (s[i + 1] - '0') > max) 
            ? throw std::logic_error("Too large number") :
                (s[i] - '0') * 10 + (s[i + 1] - '0');
    }
    
    struct time { 
        int hour; int minute; int second; 
        
        template<std::size_t N>
        constexpr time(const char (&datestr)[N]) :
            hour(date_component(datestr, 0, false, 24)), 
            minute(date_component(datestr, 3, false, 60)),
            second(date_component(datestr, 6, true, 60)) 
        {}
    };
    
    struct time constexpr midnight("00:00:00");
    struct time constexpr afternoon("12:00:00");
    
    int main(int argc, char* argv[]) {
        std::cout << "Midnight hour is " << midnight.hour << std::endl;
        std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
    }

    C++ и даты времени компиляции

    myaut, 03 Апреля 2015

    Комментарии (21)
  6. Си / Говнокод #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)
  7. PHP / Говнокод #17645

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    namespace MultipleHashMapQueueMessageRetrieverCriterias\Domain\MultipleHashMapQueueMessageRetrieverCriterias\Adapters\Exceptions;
    use MultipleHashMapQueueMessageRetrieverCriterias\Domain\Exceptions\MultipleHashMapQueueMessageRetrieverCriteriaException;
    
    final class CannotConvertMultipleHashMapQueueMessageRetrieverCriteriaToMultipleQueueMessageRetrieverCriteriaException extends MultipleHashMapQueueMessageRetrieverCriteriaException {
        const CODE = 1;
        public function __construct($message, MultipleHashMapQueueMessageRetrieverCriteriaException $parentException = null) {
            parent::__construct($message, self::CODE, $parentException);
        }
    }

    http://www.reddit.com/r/lolphp/comments/2vrgr6/irestfulmultiplehashmapqueuemessageretri evercriter/
    https://github.com/irestful/MultipleHashMapQueueMessageRetrieverCrit erias/blob/master/MultipleHashMapQueueMessageRetrieverCrit erias/Domain/MultipleHashMapQueueMessageRetrieverCrit erias/Adapters/Exceptions/CannotConvertMultipleHashMapQueueMessage RetrieverCriteriaToMultipleQueueMessageR etrieverCriteriaException.php

    Алсо, обратите внимание на структуру гитхабовских репозиториев

    myaut, 15 Февраля 2015

    Комментарии (8)
  8. Java / Говнокод #16623

    +78

    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
    /*org.eclipse.swt.internal.gtk.OS*/
    
    	public static final boolean IsAIX, IsSunOS, IsLinux, IsHPUX;
    	static {
    		
    		/* Initialize the OS flags and locale constants */
    		String osName = System.getProperty ("os.name");
    		boolean isAIX = false, isSunOS = false, isLinux = false, isHPUX = false;
    		if (osName.equals ("Linux")) isLinux = true;
    		if (osName.equals ("AIX")) isAIX = true;
    		if (osName.equals ("Solaris")) isSunOS = true;
    		if (osName.equals ("SunOS")) isSunOS = true;
    		if (osName.equals ("HP-UX")) isHPUX = true;
    		IsAIX = isAIX;  IsSunOS = isSunOS;  IsLinux = isLinux;  IsHPUX = isHPUX;
    	}

    PHP и даты Жава и Оси

    myaut, 31 Августа 2014

    Комментарии (76)
  9. bash / Говнокод #14289

    −119

    1. 1
    echo `getent passwd | awk -F: '{ if($1 == "myaut") print $3; }'`

    Определяет id пользователя myaut. Откопано в старой (моей) переписке. Эх...

    myaut, 27 Декабря 2013

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (connfailed) {
    			KSOCKET_CALLBACK(so, disconnected, error);
    		} else {
    			KSOCKET_CALLBACK(so, connectfailed, error);
    		}

    https://github.com/joyent/illumos-joyent/blob/master/usr/src/uts/common/fs/sockfs/socknotify.c

    myaut, 17 Декабря 2013

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

    +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
    /*
        * Now do an in-place copy.
        * Map (R) to (r) and (TM) to (tm).
        * The era of teletypes is long gone, and there's
        * -really- no need to shout.
        */
    while (*src != '\0') {
        if (src[0] == '(') {
            if (strncmp(src + 1, "R)", 2) == 0) {
                (void) strncpy(dst, "(r)", 3);
                src += 3;
                dst += 3;
                continue;
            }
            if (strncmp(src + 1, "TM)", 3) == 0) {
                (void) strncpy(dst, "(tm)", 4);
                src += 4;
                dst += 4;
                continue;
            }
        }
        *dst++ = *src++;
    }
    *dst = '\0';

    Не говнокод, но забавно.
    Инициализация процессоров (и сбор cpuid) в Solaris
    http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/i86pc/os/cpuid.c#2488

    myaut, 03 Мая 2013

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