can we use templates in Avr Gcc
2006-08-17 by Naveen Koul
Yahoo Groups archive
Index last updated: 2026-04-28 22:41 UTC
Thread
2006-08-17 by Naveen Koul
hi, can we use templates in avr gcc. If yes then how. Regards Naveen [Non-text portions of this message have been removed]
2006-08-17 by Jim Wagner
Naveen - There is an avr-gcc forum on the AVRFreaks website. That is the best place to ask questions above gcc! Jim On Thu, 17 Aug 2006 12:50:38 +0530 "Naveen Koul" <ernaveenkoul@gmail.com> wrote: > hi, > > can we use templates in avr gcc. If yes then how. > > Regards > > Naveen > > > [Non-text portions of this message have been removed] > > > > --------------------------------------------------------------- The Think Different Store http://www.thinkdifferentstore.com/ For All Your Mac Gear ---------------------------------------------------------------
2006-08-17 by Ned Konz
Naveen Koul wrote:
> can we use templates in avr gcc.
Yes, but...
You'll have to write your own.
Forget about standard compliance, because...
The C++ standard library is not available, so you won't have the STL
available. Nor the various support functions
You may have to write your own trivial global operator new and delete,
if you're using any dynamic memory. Likewise for the unimplemented
virtual method handler. These are below, in very simple form.
You may get unnecessary global constructors generated.
I've been writing my own templates, and have had excellent results with
the code produced (especially by AVR-gcc v 4.2.0).
I've even done a couple of little programs for the RAM-less AVRs
(ATTiny15L, for instance) and have been able to get by without needing RAM.
Some handy little things:
---------- inline.h
/// \brief Used on the declaration/definition of an inline function or
method.
/// Tries to force the compiler to inline it, even without optimization
being
/// active.
#define INLINE __attribute__((always_inline)) inline
---------- new.h
/*! \file new.h Stubs for global operator new, operator delete
* #include "new.h"
*/
#ifndef INCLUDED_INCLUDE_NEW_H
#define INCLUDED_INCLUDE_NEW_H
// \brief define if you don't need ::new() and ::delete()
#define DONT_USE_NEW 1
#if !defined(DONT_USE_NEW)
extern void *operator new(size_t) throw();
#endif
extern void operator delete(void *);
extern "C" {
extern void __cxa_pure_virtual(); // pure virtual handler
}
#endif /* INCLUDED_INCLUDE_NEW_H */
---------- new.cpp
/*! \file new.cpp Implementation of global operator new,
* operator delete, pure virtual trap
*/
extern "C" {
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
}
#include "new.h"
#if !defined(DONT_USE_NEW)
void *
operator new(size_t sz) throw()
{
void * retval = malloc(sz);
assert(retval != 0);
return retval;
}
#endif
void
operator delete(void *p)
{
#if defined(DONT_USE_NEW)
(void)p;
abort();
#else
free(p);
#endif
}
void
__cxa_pure_virtual()
{
abort();
}
Enjoy,
--
Ned Konz
ned@bike-nomad.com
http://bike-nomad.com2006-08-19 by Naveen Koul
hi,
is there any difference in the makefile that is to created for c and c++
files.
as i have file name.cc should i direclty add in make file SRC = name.cc or
name.cpp
i dont how to do it for c++ files.
Regarding my own templates can you give me a better idea on it so that i
can make it.
Regards
Naveen
On 8/18/06, Ned Konz <ned@bike-nomad.com> wrote:
>
> Naveen Koul wrote:
>
> > can we use templates in avr gcc.
>
> Yes, but...
>
> You'll have to write your own.
>
> Forget about standard compliance, because...
>
> The C++ standard library is not available, so you won't have the STL
> available. Nor the various support functions
>
> You may have to write your own trivial global operator new and delete,
> if you're using any dynamic memory. Likewise for the unimplemented
> virtual method handler. These are below, in very simple form.
>
> You may get unnecessary global constructors generated.
>
> I've been writing my own templates, and have had excellent results with
> the code produced (especially by AVR-gcc v 4.2.0).
>
> I've even done a couple of little programs for the RAM-less AVRs
> (ATTiny15L, for instance) and have been able to get by without needing
> RAM.
>
> Some handy little things:
>
> ---------- inline.h
>
> /// \brief Used on the declaration/definition of an inline function or
> method.
> /// Tries to force the compiler to inline it, even without optimization
> being
> /// active.
> #define INLINE __attribute__((always_inline)) inline
>
> ---------- new.h
>
> /*! \file new.h Stubs for global operator new, operator delete
> * #include "new.h"
> */
> #ifndef INCLUDED_INCLUDE_NEW_H
> #define INCLUDED_INCLUDE_NEW_H
>
> // \brief define if you don't need ::new() and ::delete()
> #define DONT_USE_NEW 1
>
> #if !defined(DONT_USE_NEW)
> extern void *operator new(size_t) throw();
> #endif
>
> extern void operator delete(void *);
>
> extern "C" {
> extern void __cxa_pure_virtual(); // pure virtual handler
> }
>
> #endif /* INCLUDED_INCLUDE_NEW_H */
>
> ---------- new.cpp
>
> /*! \file new.cpp Implementation of global operator new,
> * operator delete, pure virtual trap
> */
>
> extern "C" {
> #include <stdint.h>
> #include <stddef.h>
> #include <stdlib.h>
> }
>
> #include "new.h"
>
> #if !defined(DONT_USE_NEW)
>
> void *
> operator new(size_t sz) throw()
> {
> void * retval = malloc(sz);
> assert(retval != 0);
> return retval;
> }
>
> #endif
>
> void
> operator delete(void *p)
> {
> #if defined(DONT_USE_NEW)
> (void)p;
> abort();
> #else
> free(p);
> #endif
> }
>
> void
> __cxa_pure_virtual()
> {
> abort();
> }
>
> Enjoy,
> --
> Ned Konz
> ned@bike-nomad.com <ned%40bike-nomad.com>
> http://bike-nomad.com
>
>
>
[Non-text portions of this message have been removed]