To eliminate unused (ordinary) function I can use:
-ffunction-sections, -fdata-section and --gc-sections.
and it works.
I know that using polymorphism, function are 'late-binding' so I suppose there is no way to decide which of the function can be remove during linkage process.
But I am using pure virtual function to force class which inherits to implement some function. Then in code I am using objects (not pointer/reference to object, so I am not using polymorphism).
pseudo code:
class BASE {
...
virtual void do_sth() = 0;
virtual void do_sth_else() = 0;
...
};
class C1 : BASE {
...
void do_sth() { //some code }
void do_sth_else() { //some code }
}
main()
{
//the do_sth_else function is never used in main
C1 obj1;
obj.do_sth();
}
Is there some method to eliminate this unused functions (do_sth_else) during linkage process?
Maybe I misunderstood something. and because of that I think there should be a way to remove this unused function. If so please explain me why, when I am NOT using pointers with virtual function there is no way to "get rid" of polymorphic overhead. :)
FYI: This code is mainly for learning purpose.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…