A few years ago I started a project in the form of pure metal (Cortex-M). When setting up the project, we decided to use the gcc toolchain with C ++ 11 / C ++ 14, etc., and even to use C ++ and rtti exceptions.
We are currently using gcc 4.9 from launchpad.net/gcc-arm-embedded (with some issue that is stopping us from currently updating a later version of gcc).
For example, I wrote a base class and a derived class (see also the example below here ):
class OutStream { public: explicit OutStream() {} virtual ~OutStream() {} OutStream& operator << (const char* s) { write(s, strlen(s)); return *this; } virtual void write(const void* buffer, size_t size) = 0; }; class FixedMemoryStream: public OutStream { public: explicit FixedMemoryStream(void* memBuffer, size_t memBufferSize): memBuffer(memBuffer), memBufferSize(memBufferSize) {} virtual ~FixedMemoryStream() {} const void* getBuffer() const { return memBuffer; } size_t getBufferSize() const { return memBufferSize; } const char* getText() const { return reinterpret_cast<const char*>(memBuffer); }
So that clients of my class can now use, for example:
char buffer[10]; FixedMemoryStream ms1(buffer, sizeof(buffer)); ms1 << "Hello World";
Now I would like to make the use of the class more convenient and introduced the following pattern:
template<size_t bufferSize> class FixedMemoryStreamWithBuffer: public FixedMemoryStream { public: explicit FixedMemoryStreamWithBuffer(): FixedMemoryStream(buffer, bufferSize) {} private: uint8_t buffer[bufferSize]; };
And now my clients can write:
FixedMemoryStreamWithBuffer<10> ms2; ms2 << "Hello World";
But now I have seen an increase in the size of the binary executable. It seems that gcc has added character information for every other instance of the FixedMemoryStreamWithBuffer template (because for some reason we use rtti).
Could there be a way to get rid of symbol information only for some specific instances of classes / templates / templates?
It is normal to get a non-portable gcc solution for this.
For some reason, we decided to prefer templates instead of preprocessor macros; I want to avoid a preprocessor solution.