How does printf() works

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

    #16
    Re: How does printf() works

    santosh said:

    <snip>
    As long as the "as if" rule is followed and there is no observable
    difference in behaviour, the compiler is free to do whatever it wants
    with your code. Or at least, I think so.
    You think correctly. The "as if" rule conquers all.

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • Johannes Bauer

      #17
      Re: How does printf() works

      Harald van Dijk schrieb:
      That was Keith Thompson, and I was trying to make it more explicit for
      the readers of this group, not for the compiler. As I mentioned, I
      wouldn't have used the cast in actual code.
      Ah, okay, first off: sorry I swapped names (reading can be kinda hard
      sometimes). With the case: now I get your point, it was kind of unclear
      to me previously.
      >I could preload
      >some library which overrides printf() - it would never get called if the
      >compiler subsituted the call by a puts().
      >
      If you do that, as far as the standard is concerned, the behaviour is
      undefined, so there are no requirements on any particular behaviour by
      any implementation.
      Oh, okay.

      Regards,
      Johannes

      --
      "PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
      meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
      Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
      Rosenberg in dse <45608268$0$571 9$9b4e6d93@news spool3.arcor-online.net>

      Comment

      • CBFalconer

        #18
        Re: How does printf() works

        Sanchit wrote:
        >
        See i have posted in a manner which can be understood. If somewhere my
        English went wrong, that doesn't stopped anyone in understanding the
        problem.
        >
        And I clearly stated the question. I wrote in second line
        >
        "Does it uses some buffer in which it stores all what needed to be
        printed and in end of program it prints that or something else.
        "
        >
        So i really wanted to know that if printf buffers or not. And if yes
        then how.
        Good. The point is that textspeak and silly abbreviations are not
        catered to here. We are quite ready to make allowances for
        language barriers, but those things are pure carelessness.

        printf doesn't just 'work'. It is actually an entrance point to an
        interpreter, which digests the format string as the program to
        execute. The only thing that counts is the end result, which is
        specified in the C standard.

        --
        [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

        • Kaz Kylheku

          #19
          Re: How does printf() works

          On Mar 22, 3:37 pm, CBFalconer <cbfalco...@yah oo.comwrote:
          Sanchit wrote:
          >
          ... snip ...
          >
          can u please tell me a source where i can read this behaviour
          >
          u hasn't posted here for some years.  
          Whereas u hasn't posted anything of value for years, if ever.

          Comment

          • jameskuyper@verizon.net

            #20
            Re: How does printf() works

            CBFalconer wrote:
            Sanchit wrote:
            ... snip ...

            can u please tell me a source where i can read this behaviour
            >
            u hasn't posted here for some years.
            According to Google, U's most recent posting was on 2007-12-04. If
            you're worried about case sensitivity, 'u plz' posted here on
            2007-02-22. Maybe you're thinking of "Eric Binmore u", who hasn't
            posted here since 1997-04-08zs

            Comment

            • pete

              #21
              Re: How does printf() works

              Amandil wrote:
              >
              On Mar 23, 2:07 am, Richard Heathfield <r...@see.sig.i nvalidwrote:
              Amandil said:

              <snip>
              I only wish I knew how to [plonk] with google...
              s/with// - i.e. stop using google,
              and get a real newsreader. (It's the
              obvious step.)
              I know, but thus far I've been too cheap. Maybe soon. Some good
              (free?) newsreaders were mentioned recently here, I started looking in
              to them.
              >
              >
              On a slightly (but only a very slightly) more serious note,
              printf is
              probably implemented as a wrapper:
              int printf(char *format, ...)
              {
              int i;
              va_list v;
              va_start(v, format);
              i = vfprintf(stdin, format, v);
              ITYM stdout, right?
              >
              Of course, right as usual ;)
              >
              va_end(v);
              return v;
              }
              .... and you really want to return (i) instead of (v), don't you?

              I have a version of min_printf in my toy library:


              minprintf is in K&R.

              --
              pete

              Comment

              Working...