pls...how this is working...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anushhprabu
    New Member
    • Sep 2006
    • 43

    pls...how this is working...

    #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}

    q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

    guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.. it is printing the same content on screen.. how ya.. how it is.. how how how??

    please......... ..........
    Last edited by anushhprabu; Oct 5 '06, 12:17 PM. Reason: error
  • smartway
    New Member
    • Oct 2006
    • 24

    #2
    hi
    #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}

    q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

    the above code will be converted into following code after preprocessing
    here k = #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}

    and we have defined q(k) in the first line

    just substitue k in the text following q(k) in the first line i.e.
    q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

    will be converted as

    main()
    {
    return!puts(#de fine q(k)main(){retu rn!puts(#k"\nq( "#k")");}"\nPRA BUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ");}

    so the whole program becomes
    #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}
    main()
    {
    return!puts(#de fine q(k)main(){retu rn!puts(#k"\nq( "#k")");}"\nPRA BUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ");
    }

    so it just prints the contents in the parenthesis of return!puts

    and the output you get is
    #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}
    PRABUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ")

    #k gives the value of k as a stream of characters
    But still I do not get what does return!puts() means If anybody knows this plz reply

    Comment

    • dush
      New Member
      • Sep 2006
      • 27

      #3
      hi

      int puts (const char * string ); is prototype and
      return value is either non-negative on success or EOF on error.

      Theres no reason for error occuring in program above so !puts() equal to 0. Which means it is actually return 0; then and thats the correct way the main function should always end.

      Comment

      • anushhprabu
        New Member
        • Sep 2006
        • 43

        #4
        Originally posted by smartway
        hi
        #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}

        q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

        the above code will be converted into following code after preprocessing
        here k = #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}

        and we have defined q(k) in the first line

        just substitue k in the text following q(k) in the first line i.e.
        q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

        will be converted as

        main()
        {
        return!puts(#de fine q(k)main(){retu rn!puts(#k"\nq( "#k")");}"\nPRA BUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ");}

        so the whole program becomes
        #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}
        main()
        {
        return!puts(#de fine q(k)main(){retu rn!puts(#k"\nq( "#k")");}"\nPRA BUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ");
        }

        so it just prints the contents in the parenthesis of return!puts

        and the output you get is
        #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}
        PRABUq(" #define q(k)main(){retu rn!puts(#k"\nq( "#k")");}") ")

        #k gives the value of k as a stream of characters
        But still I do not get what does return!puts() means If anybody knows this plz reply
        thankq man.. i was confused for past two days with that code..
        i think - - -- actually puts will return the number of characters printed on screen.. here it is greater than 1 so it'll be returned as 0; nothing but after printing , the program gets terminated..

        i'm sure abt it.. if any corretion pls.. tell me i'll learn

        Comment

        • rajapratap
          New Member
          • Oct 2006
          • 2

          #5
          Originally posted by anushhprabu
          #define q(k)main(){ return!puts(#k" \nPRABUq("#k")" );}

          q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})

          guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.. it is printing the same content on screen.. how ya.. how it is.. how how how??

          please......... ..........
          does the stmt
          q(#define q(k)main(){retu rn!puts(#k"\nq( "#k")");})
          works???????

          Comment

          • gasfusion
            New Member
            • Sep 2006
            • 59

            #6
            i don't know what it means and i don't even want to bother looking at it. One of the primary aspects of writing code is making it readable and understandable to others. This is not how you write code.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              Originally posted by gasfusion
              i don't know what it means and i don't even want to bother looking at it. One of the primary aspects of writing code is making it readable and understandable to others. This is not how you write code.
              Unless you happen to be entering the obviscated code contest :D

              Comment

              • tyreld
                New Member
                • Sep 2006
                • 144

                #8
                For anybody using a gcc compiler you can use the -E option to only run your code through the preprocessor. It will print out your code with all of the macro substitutions expanded.

                "gcc -E file.cpp"

                Comment

                Working...