Re: inline operator delete redefinition and in-charge deleting destructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



including "new" in i.h will certainly make the example work (and would 
certainly be of better style), but I would like to know if it is just a 
workaround in order to comply with the new C++ ABI or is it mandatory by the 
langage ? 

The compiler generates implicit calls to "delete", so the programmer is not 
faulty not have included the "delete" definition in ddef.cxx.

The real problem is that I have a very different behavior in case "delete" is 
not inlined (e.g heuristic decided not to), because this way my "delete" 
contribution becomes externally visible, in particular from the 
deleting-destructor. I don't think that "inline" should change the semantic 
of a program when not unspecified.

Would it be possible in order to to fix this behavior that the compiler always 
emits the function body of inlined memory operators, the rational is that the 
compiler might instantiate calls to those and need the contribution ? (To: 
gcc-bugs)

Best Regards and thanks,

--- i.h ---
class MyClass
{
public:
  virtual ~MyClass(void);
};


--- new ---
extern int glob;

inline void operator delete(void *p)
{
  glob++;
}

--- ddef.cxx ---
#include "i.h"

MyClass::~MyClass(void)
{
}

--- foo.cxx ---
#include <stdio.h>
#include "i.h"

// explicit call to delete. include definition
#include "new"

int glob;

main()
{
  MyClass *b = new MyClass;
  delete b;

  if (glob != 1)
    printf ("FAILED %d\n", glob);
  else
    printf ("SUCCESS\n");
}


----- Original Message ----- 
From: "Eljay Love-Jensen" <eljay@xxxxxxxxx>
To: "Christian BRUEL" <christian.bruel@xxxxxx>; <gcc-help@xxxxxxxxxxx>
Sent: Tuesday, May 11, 2004 5:54 PM
Subject: Re: inline operator delete redefinition and in-charge deleting
destructor


> Hi Christian.
>
> You need...
> #include "new"
> ... at the top of your i.h file.
>
> Also, destructors have () parameter specification, not (void) for their
> parameters.
>
> Also, your header files should have guards to make sure they are only
> included once.
>
> Also, C++ uses...
> #include <cstdio>
> ... not...
> #include <stdio.h>
>
> Also, you may want to change the name of your "new" header file to
> "mynew.h" or "mynew.hxx" or "mynew.hpp".  I prefer the first convention.
>
> Style point:  MyClass* b = new MyClass; (the C++ way) is preferable to
> MyClass *b = new MyClass; (the C way).
>
> Style point:  you should put the "extern int glob;" in a header file,
> instead of hard coded.
>
> HTH,
> --Eljay
>
>
>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux