Announcement

Collapse
No announcement yet.

valgrind sucks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Oh, I have. But I kind of doubt this is a compiler bug...

    Comment


    • #32
      Library bug than?

      Can you get access to the library source?

      JM
      Jon Miller-
      I AM.CANADIAN
      GENERATION 35: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.

      Comment


      • #33
        I have no desire to debug glibc.

        Comment


        • #34
          Originally posted by Asher View Post
          Sidenote: This thread reminds me of one of my favourite interview questions: How should you handle a destructor that fails?

          I can provide a solution if someone wants it.
          I'm interested

          Comment


          • #35
            Originally posted by Asher View Post
            So everyone knows the answer to the destructor question?
            I don't believe you can provide a universally applicable answer. It depends on the application - in particular, it depends on the reason for needing the destructor in the first place.

            Comment


            • #36
              Originally posted by Kuciwalker View Post
              I don't believe you can provide a universally applicable answer. It depends on the application - in particular, it depends on the reason for needing the destructor in the first place.
              Assuming you'd like to know of the failures, there's only one way.

              So, for a constructor you should throw an exception. Can't use return values, they have no return value. You could also just log it, but this isn't really helpful.

              For a destructor, you cannot do a return value...obviously. You also should not under any circumstances throw an exception. The only thing you could possibly do is log it, or ignore it. Logging is preferred. The standard allows you to throw an exception, but it is very dangerous.

              That's the easy answer, but in the interview the meat is the follow-up question: Why not throw an exception?.

              The main problem is that it puts the C++ runtime in a bad state if an exception is thrown during the process of unwinding the stack. The stack gets unwound when code throws an exception (so "throw Blah()" will unwind the stack all the way from the throw statement to the catch statement). The process of unwinding destroys all local objects that got popped. If one of those objects throws another exception, the C++ runtime has no proper recourse. Say you do a throw Blah() and it starts unwinding objects, one of which has a destructor which throws a Blee(). At this point, it doesn't know which catch to go to. Either choice will ignore at least one catch block.

              So the C++ standard defines a course of action. It calls terminate(). The app dies, period. If you didn't deallocate everything, tough ****, it's done.

              If that makes sense.

              It's a terrific question because it not only asks about good programming practice, but to answer the "why" question the person needs to have a pretty clear understanding of how C++ works or at least have very strong ability to reason through things, if given a couple hints.
              "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
              Ben Kenobi: "That means I'm doing something right. "

              Comment


              • #37
                Another question I'll always ask regarding destructors is: "When should your destructor be virtual, and why?"

                For similar reasons to the other question.
                "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                Ben Kenobi: "That means I'm doing something right. "

                Comment


                • #38
                  Originally posted by Asher View Post
                  Assuming you'd like to know of the failures, there's only one way.

                  So, for a constructor you should throw an exception. Can't use return values, they have no return value. You could also just log it, but this isn't really helpful.

                  For a destructor, you cannot do a return value...obviously. You also should not under any circumstances throw an exception. The only thing you could possibly do is log it, or ignore it. Logging is preferred. The standard allows you to throw an exception, but it is very dangerous.

                  That's the easy answer, but in the interview the meat is the follow-up question: Why not throw an exception?.

                  The main problem is that it puts the C++ runtime in a bad state if an exception is thrown during the process of unwinding the stack. The stack gets unwound when code throws an exception (so "throw Blah()" will unwind the stack all the way from the throw statement to the catch statement). The process of unwinding destroys all local objects that got popped. If one of those objects throws another exception, the C++ runtime has no proper recourse. Say you do a throw Blah() and it starts unwinding objects, one of which has a destructor which throws a Blee(). At this point, it doesn't know which catch to go to. Either choice will ignore at least one catch block.

                  So the C++ standard defines a course of action. It calls terminate(). The app dies, period. If you didn't deallocate everything, tough ****, it's done.

                  If that makes sense.

                  It's a terrific question because it not only asks about good programming practice, but to answer the "why" question the person needs to have a pretty clear understanding of how C++ works or at least have very strong ability to reason through things, if given a couple hints.
                  Oh, you're talking about specifically in C++land (I don't know C++). I thought it was a more general question. None of your reasoning applies to C constructors or destructors.

                  Comment


                  • #39
                    C constructors and destructors?
                    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                    Ben Kenobi: "That means I'm doing something right. "

                    Comment


                    • #40
                      Yes.

                      Comment


                      • #41
                        Go on
                        "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                        Ben Kenobi: "That means I'm doing something right. "

                        Comment


                        • #42
                          Code:
                          typedef struct point_s {
                          	int x;
                          	int y;
                          } point_t;
                          
                          // constructor
                          point_t* point_create(int x, int y)
                          {
                          	point_t p = malloc(sizeof(point_t));
                          	if (!p) return NULL;
                          	point_init(p, x, y);
                          	return p;
                          }
                          
                          //initializer
                          void point_init(point_t* p, int x, int y)
                          {
                          	p->x = x;
                          	p->y = y;
                          }
                          etc.

                          Comment


                          • #43
                            That ain't no language construct though.
                            "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                            Ben Kenobi: "That means I'm doing something right. "

                            Comment


                            • #44

                              Comment


                              • #45
                                Actually, it (well, a variant of it) is a language construct in RTSC, the extension of C we use at work.

                                Comment

                                Working...
                                X