lpcware

C++ pure virtual class with newlib

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by franku on Sun Aug 19 11:41:17 MST 2012
Hi out there, I hope someone can give me a hint on a problem building a c++ static library using newlib and lpcxpresso. Everything works fine, bit I have a size-problem.

I have got a class that has pure virtual methods. Another class derives this base class and implements the function:


class A {
public:
   virtual void method() = 0;
}
class B : public A {
   virtual void method() { // do something }
}
Using the above code links appr. 60kB more code from newlib into the application than if I use the following code, where the base class method is already implemented but overwritten in the derived class:


class A {
public:
   virtual void method() {} // <-- the only change
}
class B : public A {
   virtual void method() { // do something }
}
I know that gcc for other small devices is capable to build this with smaller code, probably with a commandline switch, but I do not know how.

Does someone have a hint on how I could prevent the compiler to  auto-implement that much functions used for the pure virtual class?

Outcomes