Live data from Hacker News

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

news.ycombinator.com

171–180 of 978 posts

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

#171
post #123

Not a question, a request: Please make __attribute__((cleanup)) or the equivalent feature part of the next C standard. It's used by a lot of current software in Linux, notably systemd and glib2. It solves a major headache with C error handling elegantly. Most compilers already support it internally (since it's required by C++). It has predictable effects, and no impact on performance when not used. It cannot be imple…

Funny you should mention that, as that feature has come up recently in mailing list discussions. We have not seen an actual proposal for adopting it yet, but features similar semantics are being discussed as a possible idea (no promises). FWIW, I don't think it would wind up being spelled with attribute syntax because we would likely want programmers to have a guarantee that the cleanup will happen (and attributes ca…

I believe the last proposal was in 2008 (ignore the try..finally stuff here): http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1298.pdf

So I guess it needs someone to take that and update it, also to pull up a full list of current Linux software which is using this feature (which as I say these days is a surprising amount).

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

#172
post #163

Now that C2x plans to make two's complement the only sign representation, is there any reason why signed overflow has to continue being undefined behavior? On a slightly more personal note: What are some undefined behaviors that you would like to turn into defined behavior, but can't change for whatever reasons that be?

Another approach would be a standard library of arithmetic routines that signal overflow. If people used them while parsing binary inputs that would prevent a lot of security bugs. The fact that this question exists and is full of wrong answers suggests a language solution is needed: https://stackoverflow.com/questions/1815367/catch-and-comput...

Take a look at N2466 2020/02/09 Svoboda, Towards Integer Safety which has some support in the committee:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2466.pdf

(signal is a strong word... maybe indicate?)

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

#173
post #167

Hello, First off thank you so much for taking the time to answer questions. As a new programmer starting with C I am trying to learn how to go from a beginner to an intermediate any recommendations of projects to help learn C? It is difficult for me to find projects that I see are "valuable" for a lack of a better term. Thank you!

One possibility is to modify some existing program to include an additional new feature. You should soon develop a sense for what works well versus what causes problems.

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

#174
post #90

What's the best way to deal with "transitive const-ness", i.e. utility functions that operate on pointers and where the return type should technically get const from the argument? (strchr is the most obvious, but in general most search/lookup type functions are like this...) Add to clarify: the current prototype for strchr is char *strchr(const char *s, int c); Which just drops the "const", so you might end up writin…

Speaking as someone who is not in the committee but has observed trends since 2003 or so, I would say that solving this problem is way beyond the scope of evolutions that will make it in C2a or even the next one.

There are plenty of programing languages that distinguish strongly between mutable and immutable references, and that have the parametric polymorphism to let functions that can use both kinds return the same thing you passed to them, though. C will simply just never be one of them.

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

#175
Can you please repeat this AMA at a later date and at a time of day when people on the west coast of the USA are awake? Alternatively, please keep it going for a few hours if you would be able to be so generous with your time! Thank you for doing this!

Do you also answer questions about the standard libraries? This is not so much a C question as a library question:

I'm wondering if Apple's Grand Central Dispatch ever made it into a more integrated role in C's libraries, or if it will forever remain an outside add-on. And whether there is anything else at that level (level in the sense of high versus low level) in the standard libraries that plays such a role, that I should read up on instead of GCD.

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

#177
post #34

Not about the language exactly, so maybe not fair game, but: how did you all find yourselves joining ISO? And maybe more generally, what's the path for someone like a regular old software engineer to come to participate in the standardization process for something as significant and ubiquitous as the C programming language?

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 the committees because I have a personal desire to reduce the amount of time it takes developers to find the bugs in their code, and one great way to reduce that is to design features to make harder to write the bugs in the first place, or to turn unbounded undefined behavior into something more manageable. Others join because they have specific features they want to see adopted or want to lend their domain expertise in some area to the committee.

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

#178

I'm trying to learn C during this quarantine times. I'm looking for good beginner-friendly opensource projects to learn from. Can you please suggest some repositories to look into?

(obviously, i'm not one of the panel members, just chiming in.)

if you're interested in looking at how C can be used in embedded realtime operating systems, i recommend diving into:

https://github.com/ARMmbed/littlefs

(i'm not affiliated.)

it's a lean, logging flash filesystem implementation and i recommend it because the research, rationales, documentation, organization, codebase, test harness, and public API ergonomics all impressed me a lot. it was written for the mbed OS, but it is so well designed that i could integrate it into any realtime OS without too much trouble. and the documentation is thorough enough that after skimming the wikipedia article for filesystems, and maybe an article on how flash chips read and write data, you'll be able to work your way through it. i learned a lot by reading through that repository.

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

#180
post #126

I'm teaching C to high schoolers as their first language, which is quite the adventure. Do you have any good advice or resources on how to introduce the way C treats the function stack and heap allocated memory? Most of my students struggle (naturally) with making sense of function scoped identifiers and pass-by-value semantics.

Curious what were the requirements to select C as a first high school language over many other choices? I imagine there's a balance of practicality (after the class), and then the usual questions about tooling, sharp edges, and ease of learning.
Post reply on HN