4 ms·
For C++ most of that is iostream. $ cat hello.cpp #include <cstdio> int main(void) { puts("Hello, World!"); } $ g++ -static hello.cpp $ du -h
by kevinnk 11y ago
For C++ most of that is iostream.
$ cat hello.cpp
#include <cstdio>
int main(void) { puts("Hello, World!"); }
$ g++ -static hello.cpp
$ du -h a.out
857K a.out
Compiling for size (-Os -fdata-sections -ffunction-sections hello.c -Wl,--gc-sections) gives 816K
With iostream I get 1.6M
- Cyph0n 11y agoInteresting point. It makes sense to use stdio.h in applications where size is the priority.
- yoklov 11y agoOr where performance is a priority, in my experience. iostream is both slow and bloated. ... I don't like it's API either (it's a horrible abuse of operator<<, and is the exact kind of thing you tell people not to do with operator overloading...)
- Cyph0n 11y agoDoes stdio.h work well with std::string? Or do you mean dumping strings entirely and just working with char arrays?
- yoklov 11y agoI just meant iostream. std::strings work fine with cstdio via std::string::c_str(). (e.g. printf("%s\n", some_string.c_str() works fine). That said, I tend to avoid std::string as well, due to other performance issues (you tend to have a lot of copies and lots of heap allocations you don't really need). That said, I work in game development, and don't have to do much string processing, and someone in another domain might find this more painful than I do.
- e12e 11y agoI had to check, but apparently that'll work for utf8 on posix (windows not so much) with unicode literals and std=c++11 (or higher presumably). Nim assumes utf8. For c++: puts(u8"World is not spelled 'wørld'");