I have some code that looks like this:
class Writable {
public:
virtual void putc(const char ch) = 0;
protected:
virtual ~Writable() {};
};
class Readable {
public:
virtual char getc() = 0;
protected:
virtual ~Readable() {};
};
Notice the two virtual functions. Compiling this (along with my other code) using arm-none-eabi-gcc, and linking with -fno-exceptions produces this output:
arm-none-eabi-size --format=berkeley bareCortexM.elf
text data bss dec hex filename
108948 2304 2372 113624 1bbd8 bareCortexM.elf
Running it again with method stubs in place of pure virtual functions yields:
arm-none-eabi-size --format=berkeley bareCortexM.elf
text data bss dec hex filename
47340 2296 304 49940 c314 bareCortexM.elf
This huge difference seems to be due to exceptions. Is there any way that I can prevent this from happening?
This is described by this blog post: Smaller binary size with C++ on baremetal (g++)