Implementation-defined behaviour

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

    Implementation-defined behaviour

    AFAIK the following is implementation-defined behaviour, am I right?:


    #include <stdio.h>


    int main(void)
    {
    int n= 0;

    printf("%d\n", n++);


    return 0;
    }
  • santosh

    #2
    Re: Implementation-defined behaviour

    Ioannis Vranos wrote:
    AFAIK the following is implementation-defined behaviour, am I right?:
    >
    #include <stdio.h>
    >
    int main(void)
    {
    int n= 0;
    printf("%d\n", n++);
    return 0;
    }
    I don't think so.

    Comment

    • Ioannis Vranos

      #3
      Re: Implementation-defined behaviour

      santosh wrote:
      Ioannis Vranos wrote:
      >
      >AFAIK the following is implementation-defined behaviour, am I right?:
      >>
      >#include <stdio.h>
      >>
      >int main(void)
      >{
      >int n= 0;
      >printf("%d\n ", n++);
      >return 0;
      >}
      >
      I don't think so.
      There are similar examples at 2.12 of K&R2.


      Two quotes from there:

      "printf("%d %d\n", ++n, power(2, n)); /* WRONG */"


      "One unhappy situation is typified by the statement

      a[i]= i++;"

      Comment

      • Eric Sosman

        #4
        Re: Implementation-defined behaviour

        Ioannis Vranos wrote:
        AFAIK the following is implementation-defined behaviour, am I right?:
        >
        >
        #include <stdio.h>
        >
        >
        int main(void)
        {
        int n= 0;
        >
        printf("%d\n", n++);
        >
        >
        return 0;
        }
        Only by quibbles: the form of "successful termination"
        returned to the host environment is implementation-defined,
        the actual new-line representation written to stdout in
        response to the '\n' is implementation-defined, and things
        of that sort.

        What aspect do you believe is not Standard-defined?

        --
        Eric Sosman
        esosman@ieee-dot-org.invalid

        Comment

        • Ioannis Vranos

          #5
          Re: Implementation-defined behaviour

          Eric Sosman wrote:
          Ioannis Vranos wrote:
          >AFAIK the following is implementation-defined behaviour, am I right?:
          >>
          >>
          >#include <stdio.h>
          >>
          >>
          >int main(void)
          >{
          > int n= 0;
          >>
          > printf("%d\n", n++);
          >>
          >>
          > return 0;
          >}
          >
          Only by quibbles: the form of "successful termination"
          returned to the host environment is implementation-defined,
          the actual new-line representation written to stdout in
          response to the '\n' is implementation-defined, and things
          of that sort.
          >
          What aspect do you believe is not Standard-defined?

          I am talking about the implementation-defined behaviour of the printf()
          call described at 2.12 of K&R2.

          Comment

          • santosh

            #6
            Re: Implementation-defined behaviour

            Ioannis Vranos wrote:
            santosh wrote:
            >Ioannis Vranos wrote:
            >>
            >>AFAIK the following is implementation-defined behaviour, am I
            >>right?:
            >>>
            >>#include <stdio.h>
            >>>
            >>int main(void)
            >>{
            >>int n= 0;
            >>printf("%d\n" , n++);
            >>return 0;
            >>}
            >>
            >I don't think so.
            >
            There are similar examples at 2.12 of K&R2.
            >
            >
            Two quotes from there:
            >
            "printf("%d %d\n", ++n, power(2, n)); /* WRONG */"
            >
            >
            "One unhappy situation is typified by the statement
            >
            a[i]= i++;"
            Well these examples are different from what you have shown above. The
            first example above invokes unspecified behaviour while the second one
            invokes undefined behaviour. The example in your first post does
            neither as far as I can see.

            Comment

            • Ian Collins

              #7
              Re: Implementation-defined behaviour

              Ioannis Vranos wrote:
              Eric Sosman wrote:
              >Ioannis Vranos wrote:
              >>AFAIK the following is implementation-defined behaviour, am I right?:
              >>>
              >>>
              >>#include <stdio.h>
              >>>
              >>>
              >>int main(void)
              >>{
              >> int n= 0;
              >>>
              >> printf("%d\n", n++);
              >>>
              >>>
              >> return 0;
              >>}
              > Only by quibbles: the form of "successful termination"
              >returned to the host environment is implementation-defined,
              >the actual new-line representation written to stdout in
              >response to the '\n' is implementation-defined, and things
              >of that sort.
              >>
              > What aspect do you believe is not Standard-defined?
              >
              >
              I am talking about the implementation-defined behaviour of the printf()
              call described at 2.12 of K&R2.
              >
              There's nothing wrong with your example, the one you cite is completely
              different. If you had tried to use n again in the printf, you would hit UB.

              --
              Ian Collins.

              Comment

              • Ioannis Vranos

                #8
                Re: Implementation-defined behaviour

                Ian Collins wrote:
                Ioannis Vranos wrote:
                >Eric Sosman wrote:
                >>Ioannis Vranos wrote:
                >>>AFAIK the following is implementation-defined behaviour, am I right?:
                >>>>
                >>>>
                >>>#include <stdio.h>
                >>>>
                >>>>
                >>>int main(void)
                >>>{
                >>> int n= 0;
                >>>>
                >>> printf("%d\n", n++);
                >>>>
                >>>>
                >>> return 0;
                >>>}
                >> Only by quibbles: the form of "successful termination"
                >>returned to the host environment is implementation-defined,
                >>the actual new-line representation written to stdout in
                >>response to the '\n' is implementation-defined, and things
                >>of that sort.
                >>>
                >> What aspect do you believe is not Standard-defined?
                >>
                >I am talking about the implementation-defined behaviour of the printf()
                >call described at 2.12 of K&R2.
                >>
                There's nothing wrong with your example, the one you cite is completely
                different. If you had tried to use n again in the printf, you would hit UB.

                So, printf("%d "%d\n", x++, x++); invokes implementation-defined
                behaviour, while printf("%d\n", x++); doesn't invoke
                implementation-defined behaviour?

                Comment

                • Dann Corbit

                  #9
                  Re: Implementation-defined behaviour

                  "Ioannis Vranos" <ivranos@nospam .no.spamfreemai l.grwrote in message
                  news:fsho27$1o9 d$1@ulysses.noc .ntua.gr...
                  Ian Collins wrote:
                  >Ioannis Vranos wrote:
                  >>Eric Sosman wrote:
                  >>>Ioannis Vranos wrote:
                  >>>>AFAIK the following is implementation-defined behaviour, am I right?:
                  >>>>>
                  >>>>>
                  >>>>#include <stdio.h>
                  >>>>>
                  >>>>>
                  >>>>int main(void)
                  >>>>{
                  >>>> int n= 0;
                  >>>>>
                  >>>> printf("%d\n", n++);
                  >>>>>
                  >>>>>
                  >>>> return 0;
                  >>>>}
                  >>> Only by quibbles: the form of "successful termination"
                  >>>returned to the host environment is implementation-defined,
                  >>>the actual new-line representation written to stdout in
                  >>>response to the '\n' is implementation-defined, and things
                  >>>of that sort.
                  >>>>
                  >>> What aspect do you believe is not Standard-defined?
                  >>>
                  >>I am talking about the implementation-defined behaviour of the printf()
                  >>call described at 2.12 of K&R2.
                  >>>
                  >There's nothing wrong with your example, the one you cite is completely
                  >different. If you had tried to use n again in the printf, you would hit
                  >UB.
                  >
                  >
                  So, printf("%d %d\n", x++, x++); invokes implementation-defined
                  so does:
                  printf("%d %d\n", x++, x);
                  behaviour, while printf("%d\n", x++); doesn't invoke
                  implementation-defined behaviour?
                  This one does not.



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

                  Comment

                  • Andrey Tarasevich

                    #10
                    Re: Implementation-defined behaviour

                    Ioannis Vranos wrote:
                    So, printf("%d "%d\n", x++, x++); invokes implementation-defined
                    behaviour, while printf("%d\n", x++); doesn't invoke
                    implementation-defined behaviour?
                    'printf("%d "%d\n", x++, x++)' invokes _undefined_ behavior. 'printf("%d
                    "%d\n", x++, x)' also invokes _undefined_ behavior.

                    'printf("%d\n", x++)' does not invoke undefined behavior.

                    "Implementa tion-defined behavior" is not immediately relevant to the
                    nature of your question.

                    --
                    Best regards,
                    Andrey Tarasevich

                    Comment

                    • Barry Schwarz

                      #11
                      Re: Implementation-defined behaviour

                      On Fri, 28 Mar 2008 05:18:31 +0200, Ioannis Vranos
                      <ivranos@nospam .no.spamfreemai l.grwrote:
                      >Ian Collins wrote:
                      >Ioannis Vranos wrote:
                      >>Eric Sosman wrote:
                      >>>Ioannis Vranos wrote:
                      >>>>AFAIK the following is implementation-defined behaviour, am I right?:
                      >>>>>
                      >>>>>
                      >>>>#include <stdio.h>
                      >>>>>
                      >>>>>
                      >>>>int main(void)
                      >>>>{
                      >>>> int n= 0;
                      >>>>>
                      >>>> printf("%d\n", n++);
                      >>>>>
                      >>>>>
                      >>>> return 0;
                      >>>>}
                      >>> Only by quibbles: the form of "successful termination"
                      >>>returned to the host environment is implementation-defined,
                      >>>the actual new-line representation written to stdout in
                      >>>response to the '\n' is implementation-defined, and things
                      >>>of that sort.
                      >>>>
                      >>> What aspect do you believe is not Standard-defined?
                      >>>
                      >>I am talking about the implementation-defined behaviour of the printf()
                      >>call described at 2.12 of K&R2.
                      >>>
                      >There's nothing wrong with your example, the one you cite is completely
                      >different. If you had tried to use n again in the printf, you would hit UB.
                      >
                      >
                      >So, printf("%d "%d\n", x++, x++); invokes implementation-defined
                      This invokes undefined behavior. The commas separating function
                      arguments are not sequence points. You are modifying x twice without
                      an intervening sequence point.
                      >behaviour, while printf("%d\n", x++); doesn't invoke
                      >implementati on-defined behaviour?

                      Remove del for email

                      Comment

                      • Philip Potter

                        #12
                        Re: Implementation-defined behaviour

                        Ioannis Vranos wrote:
                        So, printf("%d "%d\n", x++, x++); invokes implementation-defined
                        behaviour, while printf("%d\n", x++); doesn't invoke
                        implementation-defined behaviour?
                        >
                        Aside from the fact that this won't compile (you have one too many "
                        characters), this is almost exactly the same question as FAQ 3.2. The
                        problem is not the individual 'x++' expressions, but the way they
                        interact with each other.

                        Philip

                        Comment

                        • Ioannis Vranos

                          #13
                          Re: Implementation-defined behaviour

                          Andrey Tarasevich wrote:
                          Ioannis Vranos wrote:
                          >So, printf("%d "%d\n", x++, x++); invokes implementation-defined
                          >behaviour, while printf("%d\n", x++); doesn't invoke
                          >implementati on-defined behaviour?
                          >
                          'printf("%d "%d\n", x++, x++)' invokes _undefined_ behavior. 'printf("%d
                          "%d\n", x++, x)' also invokes _undefined_ behavior.
                          >
                          'printf("%d\n", x++)' does not invoke undefined behavior.
                          >
                          "Implementa tion-defined behavior" is not immediately relevant to the
                          nature of your question.

                          K&R2 mentions the following:

                          "printf("%d %d\n", ++n, power(2,n)); /* WRONG */

                          can produce different results with different compilers, depending on
                          whether n is incremented before power is called".


                          That's why I call it implementation-defined behaviour.

                          Comment

                          • Eric Sosman

                            #14
                            Re: Implementation-defined behaviour

                            Ioannis Vranos wrote:
                            Eric Sosman wrote:
                            >Ioannis Vranos wrote:
                            >>AFAIK the following is implementation-defined behaviour, am I right?:
                            > [...]
                            > What aspect do you believe is not Standard-defined?
                            I am talking about the implementation-defined behaviour of the printf()
                            call described at 2.12 of K&R2.
                            Aha! This problem is explained on pages 366-7 of the
                            Frobozz Magic C version 42 Release Notes and Do-It-Yourself
                            Lobotomy Manual. Read it, and get back to me if there's
                            anything that's still unclear.

                            --
                            Eric Sosman
                            esosman@ieee-dot-org.invalid

                            Comment

                            • Richard Tobin

                              #15
                              Re: Implementation-defined behaviour

                              In article <kqidnUJehahkeH HanZ2dnUVZ_ramn Z2d@comcast.com >,
                              Eric Sosman <esosman@ieee-dot-org.invalidwrot e:
                              Aha! This problem is explained on pages 366-7 of the
                              >Frobozz Magic C version 42 Release Notes and Do-It-Yourself
                              >Lobotomy Manual.
                              I have a copy of the Encyclopedia Frobozzica on my bookshelf next to
                              K&R 2, but I've never seen the manual you mention. Is it still
                              available?

                              -- Richard

                              --
                              :wq

                              Comment

                              Working...