Thread: Compiling preprocesed code in Visual Studio 2008

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    Compiling preprocesed code in Visual Studio 2008

    Hi, I'm a student studying computer engineering at a university so please forgive any stupid things I might say.

    I was given an assignment from a professor asking to basically analyze some code and describe whether it was functional or not. Based on what I can gather from hints given by the professor, I believe what we were given was code that was already compiled. It's unlike anything I've come across, but like I said, I'm a student so there is a lot I haven't seen. My question is how can I compile this code and run it using Visual Studio 2008?

    Thanks in advance for any help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well I suppose you could either post the code, or add it to an empty project in VS2008 and try to compile it, to see what error messages you get.
    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.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    I did try adding it to an empty project and compiling it. I got several errors which I had expected (things like variables not being defined before use, errors with the function declaration "main", and some other obscure errors). I've posted the code below.

    Code:
    #include <stdio.h>
    
    main(t,_,a)
    char *a;
    {
    return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):
    1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
    main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+
    ,/#\
    ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
    q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw'
    i;# \
    ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
    iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
    ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n'
    ')# \
    }'+}##(!!/")
    :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
    :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
    "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m
    .vpbks,fxntdCeghiry"),a+1);
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    I think your professor is an idiot.

    Is he supposed to be teaching you how to program, or perform stupid magic tricks?

    Here, for what it's worth, is where your prof ripped the "code".
    Previous IOCCC Winners
    Look at phillipps, 1988

    Then read around the rest of the site to understand the motivations of IOCCC coding. It has nothing to do with programming in the real world.
    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.

  5. #5

  6. #6
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    Ugh, I'd have to agree with you. She was giving all these misleading 'hints' that went against all sound programming logic. It was no where near what was actually wrong with the code. After a couple of code fixes, it ran perfectly fine.

    Beside that, this is a pretty cool bit of code! Sure it has no real world application, but it probably encourages beginners like me to look at programming a solution from a different, more complicated angle. I wouldn't have thought of doing anything like this to print out the twelve days of Christmas.

    Thanks for the help!

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by SolidSnake745 View Post
    I did try adding it to an empty project and compiling it. I got several errors which I had expected (things like variables not being defined before use, errors with the function declaration "main", and some other obscure errors). I've posted the code below.

    Code:
    #include <stdio.h>
    
    main(t,_,a)
    char *a;
    {
    return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):
    1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
    main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
    "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+
    ,/#\
    ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
    q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw'
    i;# \
    ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
    iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
    ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n'
    ')# \
    }'+}##(!!/")
    :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
    :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
    "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m
    .vpbks,fxntdCeghiry"),a+1);
    }
    Whoever wrote that should be shot!

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Like I said, IOCCC entries are from some rather inventive programmers with way too much time on their hands.

    And no, you never see such code in the real world.

    > but it probably encourages beginners like me to look at programming a solution from a different, more complicated angle
    Actually, we prefer simplicity.
    It should be bleedingly obvious what code is doing, otherwise you spend far too much time on it.

    Think how much time you've spent on those few lines already. Now imagine how long it would have taken you if the code had been written in the obvious way.

    Now imagine there was a bug in the code (say it printed "Silver rings" rather than "Gold rings"), and how long it would take you to implement the change.

    It ought to take you minutes and seconds, not hours and days.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. writing a dll in visual studio 2008
    By xixpsychoxix in forum Windows Programming
    Replies: 4
    Last Post: 09-14-2009, 03:13 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM