On 05/02/2011 07:47, Bradley Jarvis wrote:
Hi I use avr-gcc for c++ code (have so for years) and wanted to use new and delete, particularly for libraries that I have written for and used in an x86 environment which I didn't want to have to convert. So I wrote the following wrapper functions, please feel free to add it to avr-libcTo go into a header file (not sure what the standard c++ header file new and delete function would normally exist in, that that is where the declarations would reside): void *operator new(size_t); void *operator new[](size_t); void operator delete(void *); void operator delete[](void *); To go into the source file: void *operator new(size_t s) { return malloc(s); } void *operator new[](size_t s) { return malloc(s); } void operator delete(void *m) { free(m); } void operator delete[](void *m) { free(m); } I have used these functions for years to get new and delete functionality into my avr-gcc code. BTW get job on the gcc avr support, it's a fantastic product. The only other thing I would like to use that is not supported are exceptions, it would make some software easier. Thanks Brad
I haven't yet done very much C++, but doesn't the new() operator have to call the function's constructor, and the delete() call it's destructor? Or is that handled by the compiler automatically after it uses new() to get the memory area?
mvh., David _______________________________________________ AVR-libc-dev mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
