PRINTF()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jt

    PRINTF()

    the statement

    printf("%d %d");

    will print the 1st 2nd initialized variables(if present)
    how is tht possible
  • Martin Ambuhl

    #2
    Re: PRINTF()

    jt wrote:
    the statement
    >
    printf("%d %d");
    >
    will print the 1st 2nd initialized variables(if present)
    What makes you think so? Just because your implementation doesn't barf
    at broken code doesn't mean whatever random thing it produces is right.
    how is tht possible
    Neither that not 'tht' are in any way guaranteed. Learn to write legal
    C; it will help you much more than your playing with broken code.

    Comment

    • Vladimir Oka

      #3
      Re: PRINTF()

      jt wrote:
      the statement
      >
      printf("%d %d");
      >
      will print the 1st 2nd initialized variables(if present)
      how is tht possible
      No, it won't.

      It will print whatever rubbish happens to be found by printf on
      the stack where it expects two ints. Your implementation may
      just happen to keep two previously initialised variables there.
      Mine has proper rubbish.

      Some would also argue it won't necessarily print a thing, as you
      don't show you printed a terminating newline anywhere. ;)

      It's undefined what happens really, as you should have supplied
      two ints.

      --
      My e-mail address is real, and I read it.

      Comment

      • CBFalconer

        #4
        Re: PRINTF()

        Vladimir Oka wrote:
        jt wrote:
        >
        > the statement
        >>
        >printf("%d %d");
        >>
        >will print the 1st 2nd initialized variables(if present)
        >how is tht possible
        >
        No, it won't.
        >
        It will print whatever rubbish happens to be found by printf on
        the stack where it expects two ints. Your implementation may
        just happen to keep two previously initialised variables there.
        Mine has proper rubbish.
        What stack? It has undefined behaviour.

        --
        [mail]: Chuck F (cbfalconer at maineline dot net)
        [page]: <http://cbfalconer.home .att.net>
        Try the download section.



        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • Vladimir Oka

          #5
          Re: PRINTF()

          CBFalconer wrote:
          Vladimir Oka wrote:
          >jt wrote:
          >>
          >> the statement
          >>>
          >>printf("%d %d");
          >>>
          >>will print the 1st 2nd initialized variables(if present)
          >>how is tht possible
          >No, it won't.
          >>
          >It will print whatever rubbish happens to be found by printf on
          >the stack where it expects two ints. Your implementation may
          >just happen to keep two previously initialised variables there.
          >Mine has proper rubbish.
          >
          What stack? It has undefined behaviour.
          Was that a necessary comment?

          I even said it was undefined -- in the bit that you snipped.

          And the reason OP was getting the behaviour he was had to do
          with his particular implementation so that was the reply he got,
          seeing as this was what he was talking about. His question was
          "how is that possible". I gave one possible theory.

          I know you've all been busy with Jacob and stack recently but I
          wasn't expecting it to spill over all of the group...

          --
          My e-mail address is real, and I read it.

          Comment

          • Richard

            #6
            Re: PRINTF()

            CBFalconer <cbfalconer@yah oo.comwrites:
            Vladimir Oka wrote:
            >jt wrote:
            >>
            >> the statement
            >>>
            >>printf("%d %d");
            >>>
            >>will print the 1st 2nd initialized variables(if present)
            >>how is tht possible
            >>
            >No, it won't.
            >>
            >It will print whatever rubbish happens to be found by printf on
            >the stack where it expects two ints. Your implementation may
            >just happen to keep two previously initialised variables there.
            >Mine has proper rubbish.
            >
            What stack? It has undefined behaviour.
            Probably the stack that his environment uses I would dare say. The one
            the debugger displays. Duh. Whether that stack is used in this case is
            another issue, but it was fairly clear what stack he meant.

            Comment

            • Peter Nilsson

              #7
              Re: PRINTF()

              Vladimir Oka <vladimir....@b topenworld.comw rote:
              CBFalconer wrote:
              Vladimir Oka wrote:
              jt wrote:
               the statement
              printf("%d %d");
              will print the 1st 2nd initialized variables(if present)
              how is tht possible
              >
              No, it won't.
              >
              It will print whatever rubbish happens to be found
              by printf on the stack where it expects two ints.
              Actually, it expects two void pointers.
              Your
              implementation may just happen to keep two previously
              initialised variables there. Mine has proper rubbish.
              What stack?  It has undefined behaviour.
              >
              Was that a necessary comment?
              Was yours?

              Martin gave the answer the OP needed.

              --
              Peter

              Comment

              • jaysome

                #8
                Re: PRINTF()

                On Mon, 03 Mar 2008 18:35:07 -0800, Peter Nilsson wrote:
                Vladimir Oka <vladimir....@b topenworld.comw rote:
                >CBFalconer wrote:
                Vladimir Oka wrote:
                jt wrote:
                 the statement
                printf("%d %d");
                will print the 1st 2nd initialized variables(if present) how is
                tht possible
                >
                No, it won't.
                >
                It will print whatever rubbish happens to be found by printf on the
                stack where it expects two ints.
                >
                Actually, it expects two void pointers.
                I thought the "%d" conversion specifier expects type int. Isn't the
                conversion specifier for a void pointer "%p"?

                The way I read your comment, you are you saying that something like this
                is acceptable?

                printf("%d %d", (void*)98, (void*)99);

                Isn't that undefined behavior?

                --
                jay

                Comment

                • Micah Cowan

                  #9
                  Re: PRINTF()

                  jaysome <jaysome@spamco p.netwrites:
                  On Mon, 03 Mar 2008 18:35:07 -0800, Peter Nilsson wrote:
                  >
                  >Vladimir Oka <vladimir....@b topenworld.comw rote:
                  >>CBFalconer wrote:
                  >Vladimir Oka wrote:
                  >jt wrote:
                  >  the statement
                  > printf("%d %d");
                  > will print the 1st 2nd initialized variables(if present) how is
                  > tht possible
                  <snip>
                  >It will print whatever rubbish happens to be found by printf on the
                  >stack where it expects two ints.
                  >>
                  >Actually, it expects two void pointers.
                  >
                  I thought the "%d" conversion specifier expects type int. Isn't the
                  conversion specifier for a void pointer "%p"?
                  Yes. I believe it's fair to say that Mr Nilsson misread. :)

                  --
                  Micah J. Cowan
                  Programmer, musician, typesetting enthusiast, gamer...

                  Comment

                  • Vladimir Oka

                    #10
                    Re: PRINTF()

                    Peter Nilsson wrote:
                    Vladimir Oka <vladimir....@b topenworld.comw rote:
                    >CBFalconer wrote:
                    >>Vladimir Oka wrote:
                    >>>Your
                    >>>implementati on may just happen to keep two previously
                    >>>initialise d variables there. Mine has proper rubbish.
                    >>What stack? It has undefined behaviour.
                    >Was that a necessary comment?
                    >
                    Was yours?
                    >
                    Martin gave the answer the OP needed.
                    I respectfully disagree.

                    The OP asked along the lines of "how is it possible that I get
                    this silly behaviour". I disagree it enhances OP's understanding
                    of software in general if he gets the answer "it's undefined
                    behaviour, don't do it (and don't think about it further)." My
                    reply offered one possible scenario that could lead to undefined
                    behaviour having the outcome seen by the OP. I believe that is
                    the reply OP needed.

                    Not to mention I also pointed out it was undefined, but that was
                    snipped from CBFalconer's response, making my reply seem incomplete.

                    --
                    My e-mail address is real, and I read it.

                    Comment

                    • Kenny McCormack

                      #11
                      Re: PRINTF()

                      In article <zbednbqbvIsjj1 DanZ2dnUVZ8u-dnZ2d@bt.com>,
                      Vladimir Oka <vladimir.oka@b topenworld.comw rote:
                      ....
                      >I respectfully disagree.
                      >
                      >The OP asked along the lines of "how is it possible that I get
                      >this silly behaviour". I disagree it enhances OP's understanding
                      >of software in general if he gets the answer "it's undefined
                      >behaviour, don't do it (and don't think about it further)." My
                      >reply offered one possible scenario that could lead to undefined
                      >behaviour having the outcome seen by the OP. I believe that is
                      >the reply OP needed.
                      >
                      >Not to mention I also pointed out it was undefined, but that was
                      >snipped from CBFalconer's response, making my reply seem incomplete.
                      Welcome to CLC.

                      I think I need to add this to my list of useful CLC-related links:



                      I'll leave it some of my anti-Clique colleagues to detail which one of
                      them is the most emblematic of CLC.

                      Comment

                      • Vladimir Oka

                        #12
                        Re: PRINTF()

                        Kenny McCormack wrote:
                        >
                        Welcome to CLC.
                        Oh, I've been here before. Sort of a regular for a while, too.

                        And, I do remember everyone -- including you. ;)


                        --
                        My e-mail address is real, and I read it.

                        Comment

                        • Peter Nilsson

                          #13
                          Re: PRINTF()

                          Micah Cowan <mi...@micah.co wan.namewrote:
                          jaysome <jays...@spamco p.netwrites:
                          Peter Nilsson wrote:
                          printf("%d %d");
                          ...
                          Actually, it expects two void pointers.
                          I thought the "%d" conversion specifier expects type
                          int. Isn't the conversion specifier for a void pointer
                          "%p"?
                          >
                          Yes. I believe it's fair to say that Mr Nilsson misread. :)
                          Indeed. Many apologies. Thanks to jaysome for picking it up.

                          --
                          Peter

                          Comment

                          • Nick Keighley

                            #14
                            Re: PRINTF()

                            On 4 Mar, 17:08, Vladimir Oka <vladimir....@b topenworld.comw rote:
                            Kenny McCormack wrote:
                            Welcome to CLC.
                            >
                            Oh, I've been here before. Sort of a regular for a while, too.
                            >
                            And, I do remember everyone -- including you. ;)
                            Kenny McCormack is a troll who mostly posts just to get a response.
                            It is best to ignore him.

                            Comment

                            • Richard

                              #15
                              Re: PRINTF()

                              Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                              On 4 Mar, 17:08, Vladimir Oka <vladimir....@b topenworld.comw rote:
                              >Kenny McCormack wrote:
                              >
                              Welcome to CLC.
                              >>
                              >Oh, I've been here before. Sort of a regular for a while, too.
                              >>
                              >And, I do remember everyone -- including you. ;)
                              >
                              Kenny McCormack is a troll who mostly posts just to get a response.
                              It is best to ignore him.
                              Translation: Kenny has my number.

                              Comment

                              Working...