Thread: 0123456789

  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659

    0123456789

    Code:
    #include<stdio.h>
    int main ( ) {
        int i;
        for(*&i=0;(&i)[0]<012;0[&i]++)putchar(060^i|060|i^060);
        putchar('\n');
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    ok... are you just bored or showing off?

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    We get it your better than us you don't need to remind us*goes home and cries*

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Code:
    main(){int i;for(*&i=0;(&i)[0]<012;0[&i]++)putchar(060^i|060|i^060);putchar(10);}

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >for(*&i=0;(&i)[0]<012;0[&i]++)putchar(060^i|060|i^060);
    The loop control is a little cliche for obfuscated code, and fluffing up the print with a no-op is rather like cheating, don't you think?
    My best code is written with the delete key.

  6. #6
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Ye know what would be ?? If the guy showing off would deign to explain it to us lesser programmers ..... That for loop control's a lil' beyond me.
    now I have to go back to my C book
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  7. #7
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    wouldn't 012 make it octal, thus the loop goes 10 times, nice. If so, that is quite obfuscated, the rest is not that difficult, except the bitwise operator part.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >If the guy showing off would deign to explain it to us lesser programmers
    Half the fun is figuring out code you don't understand. The other half is writing code that nobody else understands.

    >That for loop control's a lil' beyond me.
    Allow me to help a bit:

    >*&i=0
    This takes the address of i (making it a pointer) and then immediately dereferences it, thus being equivalent to i = 0.

    >(&i)[0] < 012
    As anyone familar with octal knows, 012 in octal is 10 in decimal. So we know that the loop goes until that weird thingy on the left hand side of the expression evaluates as 10. &i makes i a pointer, so you can perform pointer arithmetic on it. Since subscripting is equivalent to pointer arithmetic from an offset, (&i)[0] is the same as *(&i + 0), which is the same as i because offset 0 from i's address is i's address.

    >0[&i]++
    Because subscripting is equivalent to pointer arithmetic from an offset, and addition is commutative, a[i] is the same as i[a]. Taking what we know from the last part of the loop, this code is the same as saying i++.

    So without all of the tricky fluff, the loop is familiar:
    Code:
    for(i=0;i<10;i++)
    My best code is written with the delete key.

  9. #9
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    We were having a similar game recently

    The winner of our little contest was this (by a friend of mine).

    [CODE]

    #include <stdio.h>

    main ()
    {
    for(short d=3204,n=0;;n=n/d*d+d)
    {
    printf("%d\n", abs(n/d));
    }
    }

    [\CODE]

    Can you figure out what it does without running it?

  10. #10
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    n is undefined here also abs is defined in <math.h> Assuming n is an int, and you include <math.h>, Does it print 0 forever??

  11. #11
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    n is undefined here also abs is defined in <math.h>
    I never noticed the undefined n before ! I'm sure it did compile and run here (with LCC-win32). Like I say, I didn't write it!


    Does it print 0 forever??
    No, it doesn't.

  12. #12
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >short d=3204,n=0
    If you look a wee bit more closely, you'll notice n is actually declared legally.

    And I think that it'll start at 0, and increment by 1 each time.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  13. #13
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Originally posted by XSquared
    >short d=3204,n=0
    If you look a wee bit more closely, you'll notice n is actually declared legally.
    Only in C99

  14. #14
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    And I think that it'll start at 0, and increment by 1 each time.
    Getting warmer!


    [QUOTE]
    >short d=3204,n=0
    If you look a wee bit more closely, you'll notice n is actually declared legally.

    [\QUOTE]

    Good point. But why can't you do that in function parameter lists?

  15. #15
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    Umm will it increase by 3204 each time?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting MINI-BASIC in MASM over to C++?
    By Paul Panks in forum Projects and Job Recruitment
    Replies: 405
    Last Post: 07-04-2009, 05:41 PM