avr-gcc-list
[Top][All Lists]
Advanced

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

AW: [avr-gcc-list] C++ on AVR 90S8515


From: Stumpf Michael
Subject: AW: [avr-gcc-list] C++ on AVR 90S8515
Date: Tue, 25 Jun 2002 08:18:46 +0200



> -----Ursprüngliche Nachricht-----
> Von: address@hidden [mailto:address@hidden]
> Gesendet: Montag, 24. Juni 2002 22:11
> An: address@hidden
> Betreff: Re: [avr-gcc-list] C++ on AVR 90S8515
>
>
> Torsten Hahn <address@hidden> wrote:
>
> > I dont know, if its very sensfull to use c++ in an device with only
> > 512 Bytes of Memory ?
>
> Why depends the use of C++ classes on available memory?

Because implementation of classes takes some effort :

  - for every class there has to be a table of member functions (the so called vtbl)
  - every member function gets an implicit argument, the 'this' pointer
  - if a class uses virtual functions then every instance of that class
    gets another implicit data member, often called vptr, which points to the vtbl
  - function calls of virtual functions do cost more for the have to dereference
    the vptr and the function pointer contained in vtbl and the do an indirect call

  - if templates are used there maybe functions generated for every combination of
    argument type - unnoticed and correct, but code size grows

And implementing C++ means all or nothing, not only a subset.

>
> E. g. writing the algorithm of an FFT using a (simple) complex class
> as a complex FFT can make writing it down much easier.  The resulting
> code should be about the same.
>
One could argue that a smart compiler could resolve the overhead for simple classes,
but regarding the origin of gcc I doubt ...

> Of course, with C++ you have to be very cautious to not waste memory
> and execution time by a simple forgotten `&' in a formal function
> argument...
>

In plain C you don't have references, so C++ would help save something which C just can't.
Still there are pointers, and effectively references are nothing very different (from implementation view)

regards,
Michael

> --
> J"org Wunsch                                         Unix
> support engineer
> address@hidden       
> http://www.interface-systems.de/~j/
> avr-gcc-list at http://avr1.org
>


reply via email to

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