Thread: The worst code you will ever see hopefully

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    The worst code you will ever see hopefully

    Reading any further will probably give you a headache...

    While searching for some code I stumbled across these codes:

    If anyone wants to confirm that this WILL compile and work go ahead...

    Code:
    int max(int a,int b)
    {
        a-=b;
        if(!a)
        goto d;
        if(a<(a-a))
        goto e;
        b+=a;
        goto f;
    d:  if(a!=b)
        goto e;
    f:  a=~b;
        goto d;
    e:  return b;
    }
    This one nearly killed me from looking at it.
    Code:
    int mymax (int(*a)(int(*)(int(*)()),int(*)(int(*)(int**))), int(*b)(int(*)
    (int(*)()),int*,int(*)(int(*)()))){return (int)((((int(*)(int(*)(int(*)()),int(
    *)(int(*)())))a)> ((int(*)(int(*)(int(*)()),int(*)(int(*)())))b))?((int(*)(
    int(*)(int(*)()),int(*)(int(*)())))a):((int(*)(int(*)(int(*)()),int(*)(int(*)(
    ))))b));??>
    The function call:
    Code:
    mymax((int(*)(int(*)(int(*)()),int(*)(int(*)(int**))))3,(int(*)(int(*)(int(*)
    ()),int*,int(*)(int(*)())))52);
    equivalent code
    Code:
    (a<b)?a:b)

    Now remember when getting mad at some newbie programmer it could be much much worse than bad syntax or lack of comments.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Ah yes, but these examples were DELIBERATELY written to be hard to read.

    If you want more examples, look for the site that hosts submissions to the obfuscated C programming contests. The obfuscated C contests are done as a challenge. And as a tongue-in-cheek swipe at bad programming techniques.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    ??>
    Is actually a }. I've never seen it useed before.
    And this
    Code:
    (int(*)(int(*)(int(*)())
    Is useless. It does nothing.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    This wasn't meant to be hard to read . . . at least, I don't think so.
    Quote Originally Posted by pianorain
    Code:
    #include<stdio.h> /*square*/
    main(_,t,_t)int*t;{for(t=&_,
    printf("input: "),scanf("%d"
    ,t),t=(int*)!(_t^_t),_t=_^_;
    _t<_*_&&+_>!(int)t;printf("\
    %d",(+_t/_<_>>(int)t?_t/_:_-
    _t/_-(int)t)<(_t%_<_>>(int)t
    ?_t%_:_-_t%_-(int)t)?+_t/_<_
    >>(int)t?_t/_:_-_t/_-(int)t:
    _t%_<_>>(int)t?_t%_:_-_t%_-(
    int)t),+!((+_t+(int)t)%+_)&&
    printf("\n"),_t++);return _t
    ^_t*-+_<<(int)t/(_+(int)t);}
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Reading any further will probably give you a headache...
    Not really. What gave me a headache was having to maintain code that was worse than those examples. And people ask my why I'm a clarity nazi.
    My best code is written with the delete key.

  6. #6
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    Not really. What gave me a headache was having to maintain code that was worse than those examples. And people ask my why I'm a clarity nazi.
    people ask YOUR why you're a clarity nazi?
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >people ask YOUR why you're a clarity nazi?
    Sometimes I forgo correct grammar for clarity. Now shoo.
    My best code is written with the delete key.

  8. #8
    Banned
    Join Date
    Jun 2005
    Posts
    594
    grammar never get you anywhere.

    go on about your day prelude no harm done.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM