to guru : strange C++ operator behaviour

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

    #16
    Re: [OT] Re: to guru : strange C++ operator behaviour


    [color=blue]
    > What you apparently fail to realize is that the compiler *cannot* detect
    > undefined behavior in general, and thus cannot assign behavior to it,
    > nor can a compiler control what happens in the computer system when a
    > program attempts to do something it shouldn't. under those circumstances.[/color]
    [color=blue][color=green]
    >> The
    >> standard may state that a specific type of coding constitutes undefined
    >> behavior under the standard, but that does NOT mean anyone actually[/color][/color]
    writes[color=blue][color=green]
    >> compilers that take malicious or bizarre actions under those[/color][/color]
    circumstances.
    [color=blue]
    > Never was the claim.[/color]


    I understand your point(s) very well. But look at what I was responding to
    again:
    [color=blue][color=green]
    >> The
    > > compiler is allowed to do whatever it wants, including formatting your
    > > harddisk.[/color][/color]

    It very clearly states the the compler is "allowed" to do whatever it wants.
    Well, as I said in my post, a compiler that does "whatever it wants",
    especially if it reformats your hard drive because of a coding error, is not
    a compiler that will sell very well, because people's hard drives will
    ineveitably get reformatted.

    -Howard





    Comment

    • tom_usenet

      #17
      Re: [OT] Re: to guru : strange C++ operator behaviour

      On 03 Oct 2003 18:12:38 GMT, "Howard" <alicebt@hotmai l.com> wrote:
      [color=blue]
      >It very clearly states the the compler is "allowed" to do whatever it wants.[/color]

      And it is! The warranty for a compiler doesn't restrict the effect of
      programs that contain bugs, and probably doesn't very much for
      programs that don't contain bugs.
      [color=blue]
      >Well, as I said in my post, a compiler that does "whatever it wants",
      >especially if it reformats your hard drive because of a coding error, is not
      >a compiler that will sell very well, because people's hard drives will
      >ineveitably get reformatted.[/color]

      It is unlikely that a bug (read undefined behaviour) will lead to a
      hdd reformat, but it has happened, and the compiler isn't to blame,
      the code is.

      However, the infamous DeathStation 2000 inserts code to reformat your
      harddisk if you dereference a null pointer or write off the end of an
      array. It hasn't sold well.

      Tom

      Comment

      • Kevin Goodsell

        #18
        Re: [OT] Re: to guru : strange C++ operator behaviour

        Howard wrote:
        [color=blue][color=green]
        >>What you apparently fail to realize is that the compiler *cannot* detect
        >>undefined behavior in general, and thus cannot assign behavior to it,
        >>nor can a compiler control what happens in the computer system when a
        >>program attempts to do something it shouldn't. under those circumstances.[/color]
        >
        >[color=green][color=darkred]
        >>>The
        >>>standard may state that a specific type of coding constitutes undefined
        >>>behavior under the standard, but that does NOT mean anyone actually[/color][/color]
        >
        > writes
        >[color=green][color=darkred]
        >>>compilers that take malicious or bizarre actions under those[/color][/color]
        >
        > circumstances.
        >
        >[color=green]
        >>Never was the claim.[/color]
        >
        >
        >
        > I understand your point(s) very well. But look at what I was responding to
        > again:
        >
        >[color=green][color=darkred]
        >>>The
        >>>compiler is allowed to do whatever it wants, including formatting your
        >>>harddisk.[/color][/color]
        >
        >
        > It very clearly states the the compler is "allowed" to do whatever it wants.
        > Well, as I said in my post, a compiler that does "whatever it wants",
        > especially if it reformats your hard drive because of a coding error, is not
        > a compiler that will sell very well, because people's hard drives will
        > ineveitably get reformatted.
        >[/color]

        Yes, in that context I see your point. Though it's technically correct,
        it's a quality-of-implementation issue - and any implementation with
        quality that low probably won't sell. But there's a difference between
        what the compiler may do (intentionally or unintentionally ) and what the
        code it generates might do when its behavior is undefined. In the latter
        case, even the best compiler can't be expected to detect and safely
        handle all instances.

        -Kevin
        --
        My email address is valid, but changes periodically.
        To contact me please use the address from a recent posting.

        Comment

        • WW

          #19
          Re: [OT] Re: to guru : strange C++ operator behaviour

          tom_usenet wrote:[color=blue]
          > However, the infamous DeathStation 2000 inserts code to reformat your[/color]

          DeathStation 9000

          --
          WW aka Attila


          Comment

          • Default User

            #20
            Re: [OT] Re: to guru : strange C++ operator behaviour

            Howard wrote:[color=blue]
            >[/color]
            [color=blue]
            > It very clearly states the the compler is "allowed" to do whatever it wants.
            > Well, as I said in my post, a compiler that does "whatever it wants",
            > especially if it reformats your hard drive because of a coding error, is not
            > a compiler that will sell very well, because people's hard drives will
            > ineveitably get reformatted.[/color]


            You seem to laboring under the misconception that what happens with
            undefined behavior is some sort error handler the compiler installed.
            That usually is not the case. Most times, you see the reaction of the
            runtime environment to the UB.

            I'll agree that the compiler doesn't format your hard drive with UB, but
            the OS damn well might. Or it may let you scribble over other values,
            silently changing them, feeding incorrect values into your nav system
            and crashing your millions of dollars space probe. Quite possible, and
            quite a bit worse than your formatted hard drive.

            The "format your HD" is a useful way to make people think about the
            situation. The idea that the system will do something sensible to cover
            up your undefined behavior needs to be knocked out of their heads.

            "I just used a deleted pointer, and it didn't give me a seg fault like
            it's supposed to. Why?"




            Brian Rodenborn

            Comment

            • Mike Wahler

              #21
              Re: [OT] Re: to guru : strange C++ operator behaviour

              "Howard" <alicebt@hotmai l.com> wrote in message
              news:blkao0$rpg @dispatch.conce ntric.net...[color=blue]
              >
              > "Mike Wahler" <mkwahler@mkwah ler.net> wrote in message
              > news:AlZeb.1121 7$RW4.3023@news read4.news.pas. earthlink.net.. .[color=green]
              > >
              > > "Howard" <alicebt@hotmai l.com> wrote in message
              > > news:blhlt1$qot @dispatch.conce ntric.net...[color=darkred]
              > > >[/color]
              > >[color=darkred]
              > > > But regardless of what "undefined behavior" means in the standard, you[/color][/color]
              > had[color=green][color=darkred]
              > > > best not sell me a compiler that formats my hard drive if I screw up[/color]
              > > simple[color=darkred]
              > > > code like this...I know a good lawyer! :-)[/color]
              > >
              > > So if I sell you a chain saw, and due to your ignorance
              > > you cut off your hand, you'll sue me? I suppose so.
              > > Only in America. :-)
              > >
              > > -Mike
              > >[/color]
              >
              > :-)
              >
              > Funny, but a bit ludicrous, Mike.[/color]

              Not at all.
              [color=blue]
              >If I buy a chain saw, I know it has the
              > capability to cut off my hand (or anything else) if I abuse it. After[/color]
              all,[color=blue]
              > it is DESIGNED to cut things off![/color]

              And the C language is designed to perform its task 'safely',
              *if used according to instructions*, just like a chain saw.
              The consequences of misuse, whether intentional or inadvertent,
              cannot be reasonably blamed upon the manufacturer of either.
              [color=blue]
              > However, writing a compiler that
              > translates the standard's meaing of "undefined behavior" into "I can[/color]
              format[color=blue]
              > his hard drive if I want" is an act of malice, or at least negligence,[/color]

              That is not what I said. "Undefined behavior" by definition,
              is *undefined*. There is no 'translation'. The language
              definition, when it indicates that its misuse results in
              undefined behavior, it is essentially saying 'out of my
              hands', I'm no longer responsible for the behavior of the
              program. The language definition *specifically identifies*
              which such misuses fall into this category. I.e. *you've
              beeen warned.*


              E.g. if language misuse results in an OS getting a spurious
              'instruction' to format a disk, set the monitor on fire or
              whatever, one cannot reasonably blame the manufacturer
              or vendor of the language implementation.

              "Intentiona l" behavior is by definition, 'defined'.
              [color=blue]
              >and
              > would definitely be actionable in a court of law (and probably not just in
              > the US either).[/color]

              You're assigning meaning where there is none.
              [color=blue]
              >Do you write programs that, if the user does not read and
              > understand your user's manual correctly, will format their hard drive?[/color]

              Of course not. You're missing the point.

              [color=blue]
              >If
              > so, please let me know what products you produce so I can avoid them! :-)[/color]

              Here, run this:

              int main()
              {
              int i;
              if(i == 42)
              ++i = i++;
              return 69;
              }

              :-)

              [color=blue]
              >
              > As a side note, the reason I brought this up is that that statement about
              > formatting someone's hard drive when undefined behavior is invoked is used
              > quite often in this newsgroup, but is, in my opinion, very misleading.[/color]

              I don't think so. I think it's a good way to convey an
              example *possible* serious consequence of undefined
              behavior. IMO many will of course naturally dismiss
              the ubiquitous 'nasal demons' example as simple
              facetiousness. An example of a real catastrophe
              is imo more representative of possible consequences
              of undefined behavior, and imo is a better incentive
              for being careful.

              If you get into your car, put it in gear, close
              your eyes, and open the throttle, the consequences
              will be "undefined" . E.g. nothing bad might happen,
              or you might end up killing several people. The
              manufacturer of the car cannot rationally be held
              responsible (except of course in U.S. courts. :-)).
              I've never seen a car's owner manual specifically
              warn against driving without watching where you're
              going.


              [color=blue]
              >The
              > standard may state that a specific type of coding constitutes undefined
              > behavior under the standard, but that does NOT mean anyone actually writes
              > compilers that take malicious or bizarre actions under those[/color]
              circumstances.

              You miss the point. Such actions will not be those of the
              compiler, but of entites and/or circumstances which *by
              definition*, are outside its control.
              [color=blue]
              > Compiler writers have customers that must be satisfied, and some (if not
              > all) of those customers are BOUND to make mistakes sometimes.[/color]

              And these mistakes are the responsibility of the *user*,
              not of the maker of the misused product.
              [color=blue]
              >It is an
              > imperative that they take at least "reasonable " actions when undefined
              > behavior is encountered[/color]

              By definition, undefined behavior, is *undefined*,
              *outside the control of the compiler*.

              I can ask you "If you're standing on a balconey above
              a crowd, holding a knife, and drop the knife over the
              rail, what will happen?"

              What will you answer? Probably something like "Someone
              might get hurt." So I tell you, "the consequences cannot
              be known, although there's a good probability that something
              bad will happen, so be careful, and of course don't do it
              intentionally." So you somehow inadvertently drop the knife,
              injuring or killing someone. Will you blame the manufacturer
              of the knife?
              [color=blue]
              >(assuming that they understand and can detect those
              > conditions in the first place).[/color]

              Here's where your argument really falls apart. *Undefined*
              implies "cannot predict the outcome."
              [color=blue]
              >Failure to do so will lose them customers,
              > and money, FAST![/color]

              Yes, intentional malice should cause loss of business,
              and possibly legal action. But what you're saying is
              like saying that your boat's manufacturer is responsible
              when it sinks or capsizes because you've overloaded it,
              disregarding any warnings about such in its owners manual.
              [color=blue]
              >(Now, if there are any compiler WRITERS out there that
              > disagree, please let us know. :-))[/color]

              I think any rational person will disagree with your
              argument.
              [color=blue]
              >
              > How about, when telling posters about the meaning of "undefined behavior",[/color]

              Please look up the dictionary meaning of 'undefined'.
              You'll see something like "unknown", or "with no meaning".

              So what could possibly be the "meaning" of something
              without meaning?
              [color=blue]
              > we leave it at that,[/color]

              I rarely leave unfounded or incorrect assertions 'at that'.
              [color=blue]
              >and don't insinuate (or outright state) that they're
              > going to lose their hard drive[/color]

              Nobody said they *will*, we (accurately) say they *could*,
              and advise caution.
              [color=blue]
              >if they make a mistake, ok?[/color]

              We're trying to convey the possible serious consequences
              of such mistakes. Since "undefined behavior" means
              *anything* can happen, of course this includes catastrophe,
              as well as no problems at all. IMO it would be irresponsible
              to *not* warn about this.

              -Mike


              Comment

              • WW

                #22
                Re: [OT] Re: to guru : strange C++ operator behaviour

                Mike Wahler wrote:[color=blue]
                > I don't think so. I think it's a good way to convey an
                > example *possible* serious consequence of undefined
                > behavior. IMO many will of course naturally dismiss
                > the ubiquitous 'nasal demons' example as simple
                > facetiousness. An example of a real catastrophe
                > is imo more representative of possible consequences
                > of undefined behavior, and imo is a better incentive
                > for being careful.[/color]

                The Ariane came down due to underfined behavior. I think it was worse than
                a formatted hard drive. :-(

                --
                WW aka Attila


                Comment

                • Mike Wahler

                  #23
                  Re: [OT] Re: to guru : strange C++ operator behaviour


                  "WW" <wolof@freemail .hu> wrote in message
                  news:blkl7u$8lm $1@phys-news1.kolumbus. fi...[color=blue]
                  > Mike Wahler wrote:[color=green]
                  > > I don't think so. I think it's a good way to convey an
                  > > example *possible* serious consequence of undefined
                  > > behavior. IMO many will of course naturally dismiss
                  > > the ubiquitous 'nasal demons' example as simple
                  > > facetiousness. An example of a real catastrophe
                  > > is imo more representative of possible consequences
                  > > of undefined behavior, and imo is a better incentive
                  > > for being careful.[/color]
                  >
                  > The Ariane came down due to underfined[/color]

                  So we need to increase the amount of the fine. :-)
                  [color=blue]
                  >behavior.[/color]
                  [color=blue]
                  > I think it was worse than
                  > a formatted hard drive. :-([/color]

                  Splatted hard dive. :-)

                  -Mike


                  Comment

                  • Howard

                    #24
                    Re: [OT] Re: to guru : strange C++ operator behaviour


                    "Default User" <first.last@com pany.com> wrote in message
                    news:3F7DD08D.2 1CBD07D@company .com...[color=blue]
                    > Howard wrote:[color=green]
                    > >[/color]
                    >[color=green]
                    > > It very clearly states the the compler is "allowed" to do whatever it[/color][/color]
                    wants.[color=blue][color=green]
                    > > Well, as I said in my post, a compiler that does "whatever it wants",
                    > > especially if it reformats your hard drive because of a coding error, is[/color][/color]
                    not[color=blue][color=green]
                    > > a compiler that will sell very well, because people's hard drives will
                    > > ineveitably get reformatted.[/color]
                    >
                    >
                    > You seem to laboring under the misconception that what happens with
                    > undefined behavior is some sort error handler the compiler installed.
                    > That usually is not the case. Most times, you see the reaction of the
                    > runtime environment to the UB.
                    >
                    > I'll agree that the compiler doesn't format your hard drive with UB, but
                    > the OS damn well might. Or it may let you scribble over other values,
                    > silently changing them, feeding incorrect values into your nav system
                    > and crashing your millions of dollars space probe. Quite possible, and
                    > quite a bit worse than your formatted hard drive.
                    >
                    > The "format your HD" is a useful way to make people think about the
                    > situation. The idea that the system will do something sensible to cover
                    > up your undefined behavior needs to be knocked out of their heads.
                    >
                    > "I just used a deleted pointer, and it didn't give me a seg fault like
                    > it's supposed to. Why?"
                    >[/color]

                    Why does everyone keep thinking I'm not understanding what undefined
                    behavior means???? I was responding to a very specific statement, which
                    said, and I quote (AGAIN):


                    "The compiler is allowed to do whatever it wants, including formatting your
                    harddisk."


                    That's all I was responding to...that person's clain the the compiler was
                    "allowed" to reformat my hard drive. And my response was that if someone
                    wrote a compiler that intentionaly reformatted my hard drive, I would sue.
                    (And I also added that such a compiler would not sell very well.)

                    -Howard







                    Comment

                    • Howard

                      #25
                      Re: [OT] Re: to guru : strange C++ operator behaviour


                      AAARRRGGH Would you just read my earlier response to WW, and the specific
                      statement I was responding to? WW stated the following:

                      "The compiler is allowed to do whatever it wants, including formatting your
                      harddisk."

                      This very explicitly is talking about an action by the compiler, and all I
                      said was that if someone wrote their compiler so that it intentionally DID
                      reformat my hard drive, I'd sue. And I followed the point with a smiley
                      face! A joke, see????????

                      BTW, I FULLY agree that there is no guarantee that your hard drive WON'T be
                      reformatted if you invoke undefined behavior. I just suggested that
                      compiler writers not make such an action simply because it is "allowed to do
                      whatever it wants".

                      Now can I please get on with my life? :-)

                      -Howard




                      Comment

                      • Default User

                        #26
                        Re: [OT] Re: to guru : strange C++ operator behaviour

                        Howard wrote:[color=blue]
                        >
                        > AAARRRGGH Would you just read my earlier response to WW, and the specific
                        > statement I was responding to? WW stated the following:
                        >
                        > "The compiler is allowed to do whatever it wants, including formatting your
                        > harddisk."[/color]

                        In the future, please make your rants more specific. Say, "the compiler
                        don't do jack when it's undefined behavior, it's the system" (your
                        choice of idiom is wide open, of course). Then we'd understand the
                        target of the rant.

                        [color=blue]
                        > Now can I please get on with my life? :-)[/color]


                        We'll see about that.




                        Brian Rodenborn

                        Comment

                        • Mike Wahler

                          #27
                          Re: [OT] Re: to guru : strange C++ operator behaviour


                          "Howard" <alicebt@hotmai l.com> wrote in message
                          news:blksm0$rpn @dispatch.conce ntric.net...[color=blue]
                          >
                          > AAARRRGGH Would you just read my earlier response to WW, and the specific
                          > statement I was responding to?[/color]

                          I did, but note that usenet message propagation is not
                          serial. Attila's reply was not visible on my server
                          when I responded to your post.
                          [color=blue]
                          > WW stated the following:
                          >
                          > "The compiler is allowed to do whatever it wants, including formatting[/color]
                          your[color=blue]
                          > harddisk."
                          >
                          > This very explicitly is talking about an action by the compiler, and all I[/color]

                          This remark was poorly phrased.
                          [color=blue]
                          > said was that if someone wrote their compiler so that it intentionally DID
                          > reformat my hard drive, I'd sue. And I followed the point with a smiley
                          > face! A joke, see????????[/color]

                          One moment while I laugh. :-)

                          But no, imo nobody (at least in the U.S.) can safely disregard as
                          humorous any threat of litigation, no matter how 'far-fetched'
                          it might seem. There is a whole industry based upon extracting
                          values from innocents based upon groundless claims. Often
                          called "ambulance chasers". Their trade is kept alive by
                          dishonest judges. Have you forgotten McDonald's and hot
                          coffee?
                          [color=blue]
                          >
                          > BTW, I FULLY agree that there is no guarantee that your hard drive WON'T[/color]
                          be[color=blue]
                          > reformatted if you invoke undefined behavior.[/color]

                          I think that was the point he was making, perhaps poorly.
                          [color=blue]
                          >I just suggested that
                          > compiler writers not make such an action simply because it is "allowed to[/color]
                          do[color=blue]
                          > whatever it wants".[/color]

                          Technically, no it's not allowed to do "whatever it wants",
                          but it is relieved of the responsibility of controlling or
                          preventing "whatever" behavior which might occur as a result
                          of using constructs specified to have undefined behavior.
                          [color=blue]
                          >
                          > Now can I please get on with my life? :-)[/color]

                          Of course. You don't feel an obligation to respond
                          to anyone who might disagree with you, do you? :-)

                          -Mike


                          Comment

                          • Mark Kerns

                            #28
                            Re: [OT] Re: to guru : strange C++ operator behaviour

                            > Why does everyone keep thinking I'm not understanding what undefined[color=blue]
                            > behavior means????[/color]

                            Maybe because you keep harping on what the *compiler* does (in spite of
                            someone reference to it). Undefined behaviour happens at *runtime*. There is
                            *no* compiler involved. Your comments about a compiler formatting your drive
                            and you suing clearly indicate you don't understand what undefined behavour
                            is (in addition to your comment that such a compiler "would not sell very
                            well"). You may have only been joking but a compiler will *not* format your
                            drive or do any other harm. It's just a parser that turns symbolic code into
                            machine language (or perhaps some other intermediate form). Only at runtime
                            will undefined behaviour actually manifest itself. If you understood that
                            even now then why in your very last post (at this writing) did you say "I
                            just suggested that compiler writers not make such an action simply because
                            it is "allowed to do whatever it wants". They don't. It's the runtime
                            environment that's the problem and by this time the compiler is long gone.


                            Comment

                            • WW

                              #29
                              Re: [OT] Re: to guru : strange C++ operator behaviour

                              Mike Wahler wrote:[color=blue][color=green][color=darkred]
                              >>> of undefined behavior, and imo is a better incentive
                              >>> for being careful.[/color]
                              >>
                              >> The Ariane came down due to underfined[/color]
                              >
                              > So we need to increase the amount of the fine. :-)[/color]

                              Hey! Coolest typo I have ever had!

                              :-0

                              --
                              WW aka Attila


                              Comment

                              • WW

                                #30
                                Re: [OT] Re: to guru : strange C++ operator behaviour

                                Howard wrote:[color=blue]
                                > Why does everyone keep thinking I'm not understanding what undefined
                                > behavior means????[/color]

                                I do because I'm mean. I was thinking to be median, but then all these
                                headaches... ;-)

                                IMO because what you write sounds like playing it down. And it is a serious
                                issue. And unless we tell to newbies that they will go blind and grow hair
                                on their palms they will keep doing undefined behavior.

                                --
                                WW aka Attila


                                Comment

                                Working...