Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:23:28+00:00 2026-06-18T07:23:28+00:00

I have some code that looks like this: class Writable { public: virtual void

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:23:29+00:00Added an answer on June 18, 2026 at 7:23 am

    This is described by this blog post: Smaller binary size with C++ on baremetal (g++)

    Provide a __cxa_pure_virtual() implementation

    If you use pure virtual functions anywhere but have disabled exceptions, you may
    notice your code suddenly inflate again.

    This happened to me, and it took a while to track down, whoops!
    Inspecting assembly listing of the final binary (from objdump -h -C -S), it looked like exceptions
    were coming back!

    One thing I tried was linking with -nostdlib, completely pulling libstdc++ out of
    the picture. I provided dummy implementations of malloc, realloc,
    free, and a few other stdlib functions I used, but then avr32-g++
    complained about something I hadn’t seen before: I was missing
    __cxa_pure_virtual().

    “Aha,” I thought, “this has to be it!” In the source of that
    particular function, found in libstdc++, is a call to
    std::terminate(), seen
    here
    . That call threw a lovely party all over my poor AVR32′s
    flash memory, trampling on -fno-exceptions on their way in.

    Anyway, __cxa_pure_virtual() is what actually gets called when you
    call a pure virtual function. Like new and delete,
    this is probably something you want to override anyway so your own
    debug/trace code can give you useful feedback. The implementation is
    straightforward, just be sure to make it extern "C" so the name doesn’t get mangled:

    extern "C" void __cxa_pure_virtual() { while(1); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some code that looks like this: class Serializer { public: template<class Type>
I have some code that looks like: class Parent { private Intermediate intermediateContainer; public
I have some code that looks like this: TheClass = TheAjaxIndicator.prop('class'); if (TheClass.indexOf('Blue') >
Originally, I have some code that looks like class Ball { public: double x
I have been reviewing some code that looks like this: class A; // defined
I have some WP7 code that looks like this: using System.Windows; using System.Windows.Threading; public
I have some code that looks like this: foreach(var obj in collection) { try
I have some code that looks like this: var MyObject = function () {
I have some code that looks like this. There is also an autoincrement field
So I have some code that looks like this: <asp:BoundField DataField=CreatedOn HeaderText=Created on SortExpression=CreatedOn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.