Tell HN: C Experts Panel – Ask us anything about C
271–280 of 978 posts
Re: Tell HN: C Experts Panel – Ask us anything about C
#272What 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.m…
Opened a random part of musl out of sheer boredom. Here's what I see:
https://git.musl-libc.org/cgit/musl/tree/include/aio.h
A bunch of return codes #defined like so (see https://git.musl-libc.org/cgit/musl/tree/src/aio/aio.c):
#define AIO_CANCELED 0 #define AIO_NOTCANCELED 1 #define AIO_ALLDONE 2
#define LIO_READ 0 #define LIO_WRITE 1 #define LIO_NOP 2
#define LIO_WAIT 0 #define LIO_NOWAIT 1
Why weren't they using an enum instead? I wouldn't sign off on this code (and I don't think it lives up to best practices).
Re: Tell HN: C Experts Panel – Ask us anything about C
#273Is it worth it to learn C in 2020 ? Will it still be a prominent language for systems programming in the future ?
You need to know enough C to interface with the OS, and enough C to talk about memory layout, memory management, dynamic libraries, ABI, etc.
Most higher language runtimes need C, even with a self hosting compiler. Not being able to work on the C parts is limiting.
You also need to know enough assembly to be able to understand what the compiler did with your own code, even if you never write assembly yourself. Not being able to compare the disassembly to the high level language to understand why it doesn't work (or is order of magnitude slower than expected) is limiting.
Re: Tell HN: C Experts Panel – Ask us anything about C
#274Why is shifting by a negative amount undefined?
Re: Tell HN: C Experts Panel – Ask us anything about C
#275 unsigned int x;
x -= x;
There's a lengthy StackOverflow thread where various C language-lawyers disagree on what the spec has to say about trap values, and under what circumstances reading an uninitialised variable causes UB. I'd appreciate an authoritative answer. Thanks for dropping by on HN!Re: Tell HN: C Experts Panel – Ask us anything about C
#276Earlier quoted context omitted.
Great question! Joining the committee requires you to be a member of your country's national body group (in the US, that's INCITS) and attend at least some percentage of the official committee meetings, and that's about it. So membership is not difficult, but it can be expensive. Many committee members are sponsored by their employers for this reason, but there's no requirement that you represent a company. I joined…
Related to that: C++ standards body seems to be quite open allowing non-members to participate (outside official votes, while respecting them when looking for consensus) is it just due to my limited observation or is the C group less open? Any plans in that regard?
Re: Tell HN: C Experts Panel – Ask us anything about C
#277Earlier quoted context omitted.
Everybody seems to draw pictures of the raw memory (word-oriented) data.
I've been doing the same! It certainly helps for strings. Pointer block diagrams (like K&R use) seem to help too. Mostly what melts their brains is the idea that an identifier can be "in two places at once" - for example, you can have a variable x declared in some scope and a function one of whose arguments is named x, and those are two different things.
Re: Tell HN: C Experts Panel – Ask us anything about C
#278Will this be addressed in future revisions of the C standard?
Re: Tell HN: C Experts Panel – Ask us anything about C
#279For example, if all past, current and contemplated hardware behaves in the same way, I assume that the standard will simply enshrine this behavior.
However, what if 99% of hardware behaves one way and 1% another? Do you set the behavior to "undefined" to accommodate the 1%? At what point to you decide that the minority is too small and you'll enshrine the majority behavior even though it disadvantages minority hardware?
---
[1] Famous examples include things like bit shift and integer overflow behavior.