This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Move GDB to C++ ?


On Wednesday 30 July 2008 14:12:45 Mark Kettenis wrote:
> Dream on. 

Well, I was not trying to get to a personal level.

> How is xfree() different from delete? Oh you have smart  
> pointers.  

Depends on whether you consider, say, std::string a smart pointer.

> You'd better make sure you use them consistently in your 
> code, otherwise you end up getting yourself in the confused state
> where you can't even tell whether there's a missing delete or not.

If objects own their resourcs, 'delete' is rarely needed outside
their destructors.

> And then you decide to use a third-party C++ library.  Now you're
> almost certainly using your smart pointer inconsistently, or worse,
> have smart pointers with different semantics.

I never, ever, mentioned smart pointers. I am talking about using
very basic C++ features like destructors.

Take as an example from the first file I opened   'prompt_for_continue'.
There's an xfree in there, needed in one codepath, not needed in the
other. Not exception safe btw, but then, we do not have exceptions,
right?

{
  char *ignore;
  ...
  ignore = gdb_readline_wrapper (cont_prompt);
  ....
  if (ignore)
    {
      ...
      xfree (ignore);
    }
   ...
}

With a C-with-classes approach that could be made to look like

{
   ...
   string_t ignore = gdb_readline_wrapper (cont_prompt);
   ...
   if (ignore)
     {
      ...
     }
   ...
}


So instead of having the code spread over 39 lines (1680..1719 in utils.c)
the code is spread over _5_ lines, it saves more than a dozen keystrokes
to create, and you do not even have to think about whether the xfree 
call goes into the if, or outside, or whatever.

And see: No 'delete'. No smart pointers. No magic.

> Yes, C++ has some features that make memory management easier in
> theory.  But they're not the magic bullet that their proponents claim
> them to be.

I am not argueing that it is a silver bullet. I am saying it helps in a fairly
wide range of situations when used cautiously.

Andre'


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]