avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] new, delete support


From: kashey
Subject: Re: [avr-libc-dev] new, delete support
Date: Fri, 02 Jun 2006 08:45:24 +0300
User-agent: Thunderbird 1.5 (X11/20060119)

Ned Konz пишет:
kashey wrote:
kashey пишет:
Ned Konz пишет:
kashey wrote:
Hi all.
When be included support new and delete functions support in avr-libc?


What do you need? Assuming you don't need the whole libstdc++ library, this will probably do what you need for typical C++ programs.


extern "C" {
#include <stddef.h>
#include <stdlib.h>
}

void *operator
new(size_t sz) throw()
{
  return malloc(sz);
}

void operator
delete(void *p)
{
    free(p);
}

extern "C" __cxa_pure_virtual();

void __cxa_pure_virtual()
{
   abort();
}


And what about calling Constructor/Destructor ?

What do you mean? That's not the job of avr-libc.

Is there some code that you want to write that won't call the constructor and destructor, given the above?

I am using a recent version of avr-gcc (4.2.0, almost) and am using templates, constructors, destructors, and so on using more or less just the above and avr-libc.

Most of my objects are static, and so the constructors get called before main() (and the destructors never do), but if there were actually an exit from my code (nowhere to go, in ROM) the destructors would also get called.
It's solution for static objects. If you can describe what i have do if I'll use dynamic object.

As example:
class KMyClass
{
   private:
      int *Array;
      int Len;
   public:
      KMyClass(int Len)
      {
         Len = len;
          Array = new int [len];
       }
      ~KMyClass()
      {
         delete [] Array;
      }
}

...
int main()
{
   KMyClass *var = new KMyClass(10);
   ...
   return 0;
}


--
Пожелания и 100 грамм принимаються, критика и маты в /dev/null






reply via email to

[Prev in Thread] Current Thread [Next in Thread]