Hacker News new | ask | show | jobs
by nrclark 2275 days ago
If I buy a copy of your book, will you abuse your position to get constexpr into C? It would be a big improvement over complex macro magic.

I'll buy an extra copy if you can get 'defer' in there too!

Those two features would really be the bee's knees :)

2 comments

This is an interesting coincidence, because I just started drafting a 'defer' paper. In general, this is not an abuse of my position. I would be happy to collaborate with you (or anyone else in the community) to develop papers and champion them to the committee. They would have to be sensible ideas, which both of yours are too.
That's awesome!!! I'm actually really interested in the semantics of how a defer{} statement might work in C. If you have any kind of a draft or anything, I'd get a kick out of reading over it.

Re: developing a paper for constexpr, that's an interesting idea. I hadn't really thought about writing one up myself but it'd be an interesting thing to try out. Can you recommend a good example proposal that I could read? Shoot me an email at nicholas dot clark on the gmail if you ever see this.

If you're looking for a low-level performance targeted language where anyone can add anything whatsoever, I've got great news! C++ already exists!
I get your point. C is not C++, and it shouldn't get every feature under the sun.

But it's also not exactly -complete-. The standards committee makes changes every few years, including language additions.

I'm a fulltime C programmer, and I would _love_ to have both of the features I suggested - for the following reasons.

- defer: I could defer a free() statement after every malloc, guaranteeing that I won't miss one or forget about it. Lots of memory leaks and file-descriptor leaks could be easily avoided if C provided 'defer' as a language feature. GCC already offers something kind of similar with its __cleanup__ attribute, and a lot of programs rely on it. How much better would it be for the language to support it natively?

- constexpr: I am _so tired_ of writing really complex macros. Like say I want to populate a lookup table for a sine-wave (for fast use in a realtime system). Wouldn't it be nice if I could just populate my lookup table with a constexpr function? Then I wouldn't need really nasty macros, and I'd also be able to ensure that the calculations all happen at compile-time.