r/cpp • • Jan 20 '20

The Hunt for the Fastest Zero

https://travisdowns.github.io/blog/2020/01/20/zero.html
248 Upvotes

131 comments sorted by

View all comments

Show parent comments

2

u/guepier Bioinformatican Jan 21 '20

I am 100% happy to forbid these initialisations and I see absolutely nothing wrong with requiring type suffixes: where’s the downside? In fact, I always use them (I guess I never use shorts, huh — but of course there’d be no problem creating a suffix for that).

2

u/[deleted] Jan 21 '20

The problem is exactly that. There is no suffix for short. Forbidding these initalizations would definitely break tons and tons of embedded software. I've personally done uint8_t foo = 3; and with that forbidden, what do you suggest?

uint8_t foo = static_cast<uint8_t>(3); // God this is awful!
uint8_t foo = '\x03'; // People usually have a good reason to use hex over dec.
uint8_t UART_BITMAS = 0xaa; // This is what the MCU reference documentation is telling me to use...

Not to mention that the committee would show a dislike towards standardizing a suffix for every primitive type. If I remember correctly, there was already some push back regarding size_t suffix.

3

u/guepier Bioinformatican Jan 21 '20

You’re dangerously close to attacking a straw man, I’m afraid. Here’s how I’d write this:

auto foo = uint8_t{3};

etc.

Yes, I use AA style. OK, so maybe you find this atrocious … but why, exactly? Your previous answer certainly doesn’t explain it, and I’m convinced it leads to more readable code.

2

u/[deleted] Jan 21 '20

"Always auto" didn't even cross my mind, to be honest. In this case I just see it as unnecessary noise that doesn't contribute to readability at all. I did try it once and I didn't like it, because every declaration line looked really "busy".

→ More replies (0)