1

I don't fully understand the vtable-layout avr-g++ uses on the AVR platform.

I found that for a class hierarchy without a virtual dtor the vtable of a type looks like

(always) 0
(always) 0
ptrToFunc1
ptrToFunc2
...

In the case of a virtual dtor it looks like

(always) 0
(always) 0
dtor
dtor
ptrToFunc1
ptrToFunc2
...

The questions are:

1) what are the first two entries for? 2) why are there two entries for dtors?

and

3) can one save the first two entries (they seem to be 0 in every case)?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
wimalopaan
  • 4,838
  • 1
  • 21
  • 39
  • 2
    ad destructors. https://stackoverflow.com/questions/44558119/why-do-i-have-two-destructor-implementations-in-my-assembly-output – Sopel Jul 06 '17 at 12:08
  • Maybe also important: avr-gcc copies vtables to ram! This waste a lot of memory and makes it often impossible to use c++ on small devices. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43745. This will never be fixed, the entry is from 2010. At this point I switched to arm devices... – Klaus Jul 06 '17 at 12:32
  • Yes, thats mostly due to the Harvard-architekture ... So theres is per class overhead in RAM and a per object overhead for the vptr. – wimalopaan Jul 06 '17 at 13:12

0 Answers0