Results 1 to 5 of 5

Thread: BuYS:Compiler magic! Share/Save - My123World.Com!

  1. #1
    Garage Member
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    83
    Blog Entries
    1

    BuYS:Compiler magic!

    Hey guys,

    Long time...Hope you are all doing well.. I made a small programming puzzle @ The compiler magic! phr33dom

    Try solving it. And FYI , kindly post the answers as comments in the blog coz i have asked the same puzzle elsewhere too and it might be useful to a larger audience which includes my college juniors as well . And yeah, it is not a trick to generate blog traffic If you feel, PM me the solutions too , i leave it up to u to submit the solutions the way you prefer.

    Got a lot of catching up to do in g4h..

    Till then ,

    Peace

    Btw: I used visual c++ 2010 , didn't try out for other compilers..will update in a day about results in gcc

    //Update 1: Made a small typo in code..re-check the link..
    Last edited by sebas_phoenix; 06-25-2012 at 10:18 AM. Reason: Compiler used!!

  2. #2
    Super Commando Dhruv abhaythehero's Avatar
    Join Date
    Sep 2010
    Location
    Lucknow/Pune,India
    Posts
    466
    Blog Entries
    2
    Quote Originally Posted by sebas_phoenix View Post
    Hey guys,

    Long time...Hope you are all doing well.. I made a small programming puzzle @ The compiler magic! phr33dom

    Try solving it. And FYI , kindly post the answers as comments in the blog coz i have asked the same puzzle elsewhere too and it might be useful to a larger audience which includes my college juniors as well . And yeah, it is not a trick to generate blog traffic If you feel, PM me the solutions too , i leave it up to u to submit the solutions the way you prefer.

    Got a lot of catching up to do in g4h..

    Till then ,

    Peace
    Heheh .. we would never see it as a "trick to generate blog traffic" . Keep posting man !
    In the world of 0s and 1s, are you a zero or The One !

  3. #3
    Garage Member
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    83
    Blog Entries
    1
    Haha, i know dude.. Just kidding...

  4. #4
    Namaste

    The compilers check for a return statement and it is present but it is present (otherwise logically compilation should generate a warning).

    Now the answer is:
    The function is typecasted to int, it should return an int and return values are prepared into eax register.

    This is the case with return line; now with else statement:

    res=num*fact(num-1);

    the res variable is might also be going inside EAX register right before the natural ending of the function i.e. the epilogue.

    And thats why due to in both cases the EAX register is getting the value, thats why this code is working correctly.

    Note: haven't checked the compiled/dissembled code, but a blind guess depending on the most of compiler's behavior.

    ..."vinnu"

  5. #5
    Garage Member
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    83
    Blog Entries
    1
    Posted the answer @ The compiler magic! phr33dom

    @Vinnu bro: the 'res' variable will go into eax, if there was an 'explicit' return statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •