Implementation-defined behaviour

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

    #16
    Re: Implementation-defined behaviour

    On 28 Mar 2008 at 3:18, 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?
    Wonderful post! This is exactly what clc is for - another thrilling
    discussion of i=i++. Hold onto your seats, folks - it's going to be an
    exciting ride.

    Comment

    • Antoninus Twink

      #17
      Re: Implementation-defined behaviour

      On 28 Mar 2008 at 12:20, Ioannis Vranos wrote:
      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
      >>implementatio n-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.
      >>
      >"Implementatio n-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.
      Don't stop now! The regulars will be wetting themselves at the chance to
      rehash so many FAQ answers!

      Comment

      • jacob navia

        #18
        Re: Implementation-defined behaviour

        Antoninus Twink wrote:
        On 28 Mar 2008 at 3:18, 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?
        >
        Wonderful post! This is exactly what clc is for - another thrilling
        discussion of i=i++. Hold onto your seats, folks - it's going to be an
        exciting ride.
        >
        Yes, there we go

        This is the *main* topic of this group:

        n=n++;

        Exciting. That is the word!

        :-)

        --
        jacob navia
        jacob at jacob point remcomp point fr
        logiciels/informatique
        http://www.cs.virginia.edu/~lcc-win32

        Comment

        • Kenny McCormack

          #19
          Re: Implementation-defined behaviour

          In article <fsitgu$h7r$1@a ioe.org>, jacob navia <jacob@nospam.o rgwrote:
          >Antoninus Twink wrote:
          >On 28 Mar 2008 at 3:18, Ioannis Vranos wrote:
          >>So, printf("%d "%d\n", x++, x++); invokes implementation-defined
          >>behaviour, while printf("%d\n", x++); doesn't invoke
          >>implementatio n-defined behaviour?
          >>
          >Wonderful post! This is exactly what clc is for - another thrilling
          >discussion of i=i++. Hold onto your seats, folks - it's going to be an
          >exciting ride.
          >>
          >
          >Yes, there we go
          >
          >This is the *main* topic of this group:
          >
          >n=n++;
          >
          >Exciting. That is the word!
          >
          >:-)
          >
          >--
          >jacob navia
          >jacob at jacob point remcomp point fr
          >logiciels/informatique
          >http://www.cs.virginia.edu/~lcc-win32
          And:

          1) How to declare main() { Always a hit! }
          2) Why not to cast the return value of *alloc()

          That's it folks. Enjoy!

          Comment

          • Eric Sosman

            #20
            Re: Implementation-defined behaviour

            Richard Tobin wrote:
            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?
            You can download it from



            They're CP/M WordStar files; pull your old Osborne out of
            the closet and you'll be able to read them. (Scrolling
            that tiny screen is sort of a pain, though.)

            --
            Eric.Sosman@sun .com

            Comment

            • Ioannis Vranos

              #21
              Re: Implementation-defined behaviour

              Kenny McCormack wrote:
              >
              And:
              >
              1) How to declare main() { Always a hit! }
              Easy. Under C90:

              int main(), int main(void), int main(int argc, char *argv[]), int
              main(int argc, char **argv), and those also with no return type
              (implicit int).

              2) Why not to cast the return value of *alloc()
              >
              That's it folks. Enjoy!

              malloc() doesn't need a cast in C, it needs in C++, because in C there
              is implicit conversion of void * to any other pointer type, but not in
              C++ where it requires a cast.

              Comment

              • Richard

                #22
                Re: Implementation-defined behaviour

                Ioannis Vranos <ivranos@nospam .no.spamfreemai l.grwrites:
                Kenny McCormack wrote:
                >>
                >And:
                >>
                >1) How to declare main() { Always a hit! }
                >
                Easy. Under C90:
                >
                int main(), int main(void), int main(int argc, char *argv[]), int
                main(int argc, char **argv), and those also with no return type
                (implicit int).
                >
                >
                >2) Why not to cast the return value of *alloc()
                >>
                >That's it folks. Enjoy!
                >
                >
                malloc() doesn't need a cast in C, it needs in C++, because in C there
                is implicit conversion of void * to any other pointer type, but not in
                C++ where it requires a cast.
                I think you miss the point. Kenny was being sarcastic because the clique
                are normally in a race to see who can answer this first in the most
                confusing and condescending manner.

                Comment

                • Kenny McCormack

                  #23
                  Re: Implementation-defined behaviour

                  In article <fsj3am$6p4$1@r egistered.motza rella.org>,
                  Richard <devr_@gmail.co mwrote:
                  >Ioannis Vranos <ivranos@nospam .no.spamfreemai l.grwrites:
                  >
                  >Kenny McCormack wrote:
                  >>>
                  >>And:
                  >>>
                  >>1) How to declare main() { Always a hit! }
                  >>
                  >Easy. Under C90:
                  >>
                  >int main(), int main(void), int main(int argc, char *argv[]), int
                  >main(int argc, char **argv), and those also with no return type
                  >(implicit int).
                  >>
                  >>
                  >>2) Why not to cast the return value of *alloc()
                  >>>
                  >>That's it folks. Enjoy!
                  >>
                  >>
                  >malloc() doesn't need a cast in C, it needs in C++, because in C there
                  >is implicit conversion of void * to any other pointer type, but not in
                  >C++ where it requires a cast.
                  >
                  >I think you miss the point. Kenny was being sarcastic because the clique
                  >are normally in a race to see who can answer this first in the most
                  >confusing and condescending manner.
                  >
                  He's kind of made your point for you, didn't he?

                  Comment

                  • Richard

                    #24
                    Re: Implementation-defined behaviour

                    gazelle@xmissio n.xmission.com (Kenny McCormack) writes:
                    In article <fsj3am$6p4$1@r egistered.motza rella.org>,
                    Richard <devr_@gmail.co mwrote:
                    >>Ioannis Vranos <ivranos@nospam .no.spamfreemai l.grwrites:
                    >>
                    >>Kenny McCormack wrote:
                    >>>>
                    >>>And:
                    >>>>
                    >>>1) How to declare main() { Always a hit! }
                    >>>
                    >>Easy. Under C90:
                    >>>
                    >>int main(), int main(void), int main(int argc, char *argv[]), int
                    >>main(int argc, char **argv), and those also with no return type
                    >>(implicit int).
                    >>>
                    >>>
                    >>>2) Why not to cast the return value of *alloc()
                    >>>>
                    >>>That's it folks. Enjoy!
                    >>>
                    >>>
                    >>malloc() doesn't need a cast in C, it needs in C++, because in C there
                    >>is implicit conversion of void * to any other pointer type, but not in
                    >>C++ where it requires a cast.
                    >>
                    >>I think you miss the point. Kenny was being sarcastic because the clique
                    >>are normally in a race to see who can answer this first in the most
                    >>confusing and condescending manner.
                    >>
                    >
                    He's kind of made your point for you, didn't he?
                    Amazing isn't it?

                    Comment

                    • pete

                      #25
                      Re: Implementation-defined behaviour

                      Ioannis Vranos wrote:
                      >
                      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
                      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.
                      >
                      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.
                      It's unspecified behavior.
                      The power(2,n) function call, introduces a sequence point
                      that the other code examples don't have.
                      This is all about sequence points.

                      --
                      pete

                      Comment

                      • pete

                        #26
                        Re: Implementation-defined behaviour

                        Richard wrote:
                        >
                        Ioannis Vranos <ivranos@nospam .no.spamfreemai l.grwrites:
                        >
                        Kenny McCormack wrote:
                        >
                        And:
                        >
                        1) How to declare main() { Always a hit! }
                        Easy. Under C90:

                        int main(), int main(void), int main(int argc, char *argv[]), int
                        main(int argc, char **argv), and those also with no return type
                        (implicit int).

                        2) Why not to cast the return value of *alloc()
                        >
                        That's it folks. Enjoy!

                        malloc() doesn't need a cast in C, it needs in C++,
                        because in C there is implicit conversion of void *
                        to any other pointer type, but not in
                        C++ where it requires a cast.
                        >
                        I think you miss the point.
                        Nope. He didn't miss the point. You did.
                        Kenny was being sarcastic because
                        Nobody cares about that.
                        That's the point.

                        --
                        pete

                        Comment

                        • Harald van =?UTF-8?b?RMSzaw==?=

                          #27
                          Re: Implementation-defined behaviour

                          On Fri, 28 Mar 2008 16:44:12 -0500, pete wrote:
                          Ioannis Vranos wrote:
                          >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.
                          >
                          It's unspecified behavior.
                          The power(2,n) function call, introduces a sequence point that the other
                          code examples don't have. This is all about sequence points.
                          If arguments are evaluated strictly from left to right (nothing wrong
                          with that), here are the steps:
                          - evaluate "%d %d\n"
                          - evaluate ++n
                          - evaluate 2
                          - evaluate n
                          * call power
                          * call printf

                          There is not necessarily any sequence point between the evaluation of ++n
                          and the evaluation of n, unless I'm missing something.

                          Comment

                          • pete

                            #28
                            Re: Implementation-defined behaviour

                            Dann Corbit wrote:
                            >
                            "Ioannis Vranos" <ivranos@nospam .no.spamfreemai l.grwrote in message
                            So, printf("%d %d\n", x++, x++); invokes implementation-defined
                            so does:
                            printf("%d %d\n", x++, x);
                            That's undefined, not implementation defined.
                            There's no sequence points in there.
                            behaviour, while printf("%d\n", x++); doesn't invoke
                            implementation-defined behaviour?
                            >
                            This one does not.
                            Of course not.
                            This is not about freaking out at the sight of an increment operator,
                            it's about sequence points.

                            --
                            pete

                            Comment

                            • pete

                              #29
                              Re: Implementation-defined behaviour

                              santosh wrote:
                              >
                              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.
                              That's the way that I see it too.

                              --
                              pete

                              Comment

                              • Harald van =?UTF-8?b?RMSzaw==?=

                                #30
                                Re: Implementation-defined behaviour

                                On Sat, 29 Mar 2008 08:10:44 +0000, Flash Gordon wrote:
                                >>>Ioannis Vranos wrote:
                                >>>>K&R2 mentions the following:
                                >>>>>
                                >>>>"printf(" %d %d\n", ++n, power(2,n)); /* WRONG */
                                [snip]
                                >
                                So in the above evaluating the parameters to the power function is
                                explicitly *required* to take place before the sequence point of calling
                                the function.
                                Evaluation of the parameters is not possible until power is actually
                                called, but evaluation of the arguments must take place earlier. :-)

                                Comment

                                Working...