3 ms·
Another interesting fact: Write a Hello World program in C++, run the preprocessor on it (g++ -E), then count the lines of the output. I just tried and it show
by qznc 3y ago
Another interesting fact: Write a Hello World program in C++, run the preprocessor on it (g++ -E), then count the lines of the output.
I just tried and it shows me 33738 lines (744 lines for C btw).
In a language like C++, even Hello World uses like half of all the language features.
- ColonelPhantom 3y agoArguably, most of that is probably dead code included from <iostream>. Most of it is likely never called for a simple Hello World. Similarly, in C, you can just give the definition of printf and omit the include of stdio.h, which also saves a ton of preprocessed lines.
- nsguy 3y agoDon't include the standard headers and just put it the definition for the symbols you're using. With std::cout you might end up pulling your hair out to find everything but I can't imagine it'd be more than a few dozen lines... Not gonna try ;) With C you just need a definition for printf instead of including stdio. In the old days you'd get by without even defining it at all.
- flohofwoe 3y ago> In the old days you'd get by without even defining it at all. GCC and Clang have a `__builtin_printf()` instead, quite useful for adhoc printf-debugging without having to include stdio.h. Under the hood it just resolves to a regular printf() or puts() stdlib call though.
- qznc 3y agoIn C, you can get away with just this (no includes or definitions): void main() { puts("Hello, World!"); } You get a warning, but it is fine.