Live data from Hacker News

Tell HN: C Experts Panel – Ask us anything about C

news.ycombinator.com

71–80 of 978 posts

Re: Tell HN: C Experts Panel – Ask us anything about C

#71

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…

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

#72

Will you ever add / have you considered adding sane formatting options for fixed length variables in printf? Say %u32 or %s64 ? Have you considered adding access to structure members by index or by string name? Have you considered dynamic structures?

> Will you ever add / have you considered adding sane formatting options for fixed length variables in printf? Say %u32 or %s64 ?

I'm not certain about the historical answer to this, but I do know that we're currently considering a proposal to introduce an exact bit-width integer type '_ExtInt(N)' to the language, and how to handle format specifiers for it is part of those discussions, so we are considering some changes in this area.

> Have you considered adding access to structure members by index or by string name? Have you considered dynamic structures?

I don't recall seeing any such proposals. I'm not familiar with the term "dynamic structures", what do you have in mind there?

Re: Tell HN: C Experts Panel – Ask us anything about C

#73

So what do people think about having a feature in the C language akin to the defer statement in GoLang? The GoLang defer statement defers the execution of a function until the surrounding function returns. The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns. It looks like an interesting mechanism for cleaning up resources.

I personally don't like golang's defer. For me it obscures the flow of the program. For example when I acquire a lock, I like to see where exactly it's released.

For me "defer" only makes sense in the context of exceptions, basically as an equivalent to "finally". This is a slippery slope though, since golang's exceptions are, for a reason, rudimentary.

Re: Tell HN: C Experts Panel – Ask us anything about C

#75
post #66

Is there any plan to deal with the locale fiasco at some point? Some hints on what I'm referring to can be found here: https://github.com/mpv-player/mpv/commit/1e70e82baa9193f6f02... Unrelated, but I also miss a binary constant notation (such as 0b10101)

In the same vein, I really like being able to use underscores in binary and hex literals to denote subfields in hardware registers.

0xDEADB_EEF

0b1_010_110111001001

etc.

Re: Tell HN: C Experts Panel – Ask us anything about C

#76
post #65

Earlier quoted context omitted.

Yes, the C2x charter has this requirement: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm

Thanks, so from "Only those features that have a history and are in common use by a commercial implementation should be considered", this precludes stuff that may only exist in clang, gcc, glibc, etc.? If so, why?

I wouldn't read into "commercial" there, I think we meant "production-quality" instead. (We should fix that!)

Basically, we prefer seeing features that real users have used as opposed to an experimental branch of a compiler that doesn't have usage experience. Knowing it can be implemented is one thing, but knowing users want to use it is more compelling.

Re: Tell HN: C Experts Panel – Ask us anything about C

#78
post #53

What are two or three C codebases that are elegantly and cleanly written, and that every mid-level C programmer should read for sake of knowledge?

I would recommend musl, although the style is a bit idiosyncratic in places: https://www.musl-libc.org

Mbed TLS, since I have it in mind from another thread, is also a pretty clean C library for the problem it tries to solve; it's a testament to its design that we (TrustInSoft, who had not participated to its development) were able to verify that some uses of the library were free of Undefined Behavior: https://tls.mbed.org

Post reply on HN