Hacker News new | ask | show | jobs
by AnimaLibera 1720 days ago
C++ is sooo much better than any other compiled language! For example, using std::cout to print the value 97 will produce different results depending on whether this value is of the type int8_t or int32_t (but in Rust, printing 97 always outputs "97" without depending on the type of 97 that can be i8, i32, whatever). This is because C++ uses C headers to typedef int into int32_t (or whatever is 32 bits on the implementation that is being used) and to typedef char into int8_t (so the value 97 of type int8_t is printed as "a"), at least that is the case with glibc. What a good language, in comparison Rust is so boring and uninteresting.
2 comments

C++ is the language I use most for my day job. I am definitely on the "love" side of the "Marmite" argument.

What is scary is, I don't doubt that some people will read your comment and think it could be true!

Don't get me wrong, C++ is interesting to work with ^^, but what I said is true (just go ahead and test it, `#include <cstdint>`, then initialize a variable of type `int8_t` and `std::cout` it, I just tried it on godbolt.org with the `x86-64 gcc 11.2` compiler and it printed the value as a character rather than as a number (unlike an `int32_t`)). I never miss an opportunity to mock C++ and its many layers of features that don't always interact well with each others. Maybe take it as a fun fact and not as an attack..
You're right! That's the thing with C++ - you learn something new everyday.

I had misread your original post. I thought the example was something like "std::cout << 97".

This is unfortunate. I imagine it came about when "cstdint" was introduced. Fixing it would require a break in compatibility with any existing code that "expected" that all char types printed a character, rather than value.

Actually when I said that in comparison Rust is boring, I was only half joking. C++ is way more fun in the sense that it feels like a patchwork with surprising interactions that can get even C++ masters. C++ dev sounds like a fun job ^^
By "glibc" i meant the GNU C++ standard library implementation, not glibc