News for hackers. Stuff that matters.
Re:Tell HN: C Experts Panel – Ask us anything about C by emilfihlman on Tuesday April 14, 2020 @09:47AM (#22865870)
Thank you for taking time to take questions!

Have you ever considered or will you consider deprecating char, int, long, (s)size_t, float, double and etc in favour of specific length types?

Will you ever add / have you considered adding [su]\d+ and f\d+ as synonyms for those mentioned stdint.h?

Since char is signed on most platforms, arm eabi being an exception and even there it's really just a matter of compile time flags, will you ever just drop char from being able to be either and just say it's signed, as int is also signed?

Will you ever define / have you considered defining signed overflow behaviour?

Re:Tell HN: C Experts Panel – Ask us anything about C by rseacord on Tuesday April 14, 2020 @10:02AM (#22866079)
I don't think we'll ever deprecate char, int, long, float, double, or size_t. ssize_t is not part of the C Standard, and hopefully never will be as it is a bit of an abomination. The main driver behind the evolution of the C Standard is not to break existing code written in C, because the world largely runs on C programs.

C does provide fixed width types like uint8_t, uint16_t, uint32_t, and uint64_t. These are optional types because they can't be implemented on implementations that don't have the appropriate word sizes. We also have required types such as

uint_least16_t uint_least32_t uint_least64_t uint_least8_t

Re:Tell HN: C Experts Panel – Ask us anything about C by tropo on Tuesday April 14, 2020 @09:19PM (#22873455)
Those types should not be optional. CHAR_BIT needs to be 8. It is clearly possible to implement the types even on a 6502 or Alpha. From the early days of pre-ANSI C, the language supported types for which the hardware did not have appropriate word sizes. There was a 32-bit long on the 16-bit PDP-11 hardware.

I would go beyond that, requiring all sizes that are a multiple of 8 bits from 8-bit through 512-bit. This better supports cryptographic keys and vector registers.

Re:Tell HN: C Experts Panel – Ask us anything about C by saagarjha on Tuesday April 14, 2020 @09:59PM (#22873689)
> CHAR_BIT needs to be 8.

Why?

Re:Tell HN: C Experts Panel – Ask us anything about C by souprock on Tuesday April 14, 2020 @11:17PM (#22874129)
Everything breaks if it isn't.

I was on an OS development team in the 1990s. We were using the SHARC DSP, which was naturally a word-addressed chip. Endianness didn't exist in hardware, since everything was whatever size (32, 40, or 48 bits) you had on the other end of the bus. Adding 1 to a hardware pointer would move by 1 bus width. The chip vendor thought that CHAR_BIT could be 32 and sizeof(long) could be 1.

We couldn't ship it that way. Customers wanted to run real-world source code and they wanted to employ normal software developers. We hacked up the compiler to rotate data addresses by 2 bits so that we could make CHAR_BIT equal to 8.

That was the 1990s, with an audience of embedded RTOS developers who were willing to put up with almost anything for performance. People are even less forgiving today. If strangely sized char couldn't be a viable product back in the 1990s, it has no chance today. It's dead. CHAR_BIT is 8 and will forever be so.

Re:Tell HN: C Experts Panel – Ask us anything about C by emilfihlman on Wednesday April 15, 2020 @01:16PM (#22880358)
This was a really interesting and enlightening comment and a small story! Thank you!
Re:Tell HN: C Experts Panel – Ask us anything about C by emilfihlman on Tuesday April 14, 2020 @10:53AM (#22866741)
>The main driver behind the evolution of the C Standard is not to break existing code written in C, because the world largely runs on C programs.

If not deprecate, then at least make fixed width types as equivalent members to them, ie all char based apis should accept s8 (typedef signed char s8) and all int based apis should accept s32.

Re:Tell HN: C Experts Panel – Ask us anything about C by rseacord on Tuesday April 14, 2020 @11:07AM (#22866888)
Well, there are number of problems with this proposal. For example, if your implementation defines int as a 16-bit type (which is permitted for by the standard) and you pass an int32_t, the value you pass maybe truncated if it is outside of the range of the narrower type. When programming, it is best to match the type of the API of the function you are calling for portability.