Remove #include <iostream> to allow compiling for small embedded systems#61
Open
timoscs wants to merge 2 commits intoimneme:masterfrom
Open
Remove #include <iostream> to allow compiling for small embedded systems#61timoscs wants to merge 2 commits intoimneme:masterfrom
timoscs wants to merge 2 commits intoimneme:masterfrom
Conversation
added 2 commits
May 26, 2020 14:29
Admittedly it's a bit brute force to just remove the header inclusions, and that it works is based on all the iostream -related code being in templates, so that when they're not used there's no problem. Of you do use them, you have to include <iostream> yourself (and I'm not 100% sure that there won't be restrictions in order of includes). Another approach, maybe more robust but less elegant, would be to #ifdef out the iostream headers if some flag (PCG_DONOTUSEIOSTREAM ? ) is defined Removing <new> is not absolutely necessary, but I'm not sure what it's used for here, the only relevant part I could find is one use of placement new?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm using the library on a 128kB STM32F4 -processor, and #include brings in about 140kB of data, which obviously won't fit in the flash. Without iostream, this library increases code size by about 400 bytes when using pcg32, which is pretty ok (although could probably still be trimmed).
Admittedly it's a bit brute force to just remove the header inclusions, and that it works at all is based on all the iostream -related code being in templates, so that when they're not used there's no problem. If you do use them, you have to include yourself and the order does matter (I had to change one of the tests to make them compile).
Another approach would be to merge pull request #4 , switching the extras header to also use forward declarations.
Yet another approach, maybe more robust but less elegant, would be to #ifdef out the iostream headers if some flag (PCG_DONOTUSEIOSTREAM ? ) is defined.
Removing is not absolutely necessary, but I'm not sure what it's used for here, the only relevant part I could find is one use of placement new?