Live data from Hacker News

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

news.ycombinator.com

561–570 of 978 posts

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

#561
I'm no C expert, but my two wishes for C would be:

- Basic type inference to reduce keystrokes, and prevent ripples when changing types. (like auto in C++)

- Equality operators defined for structs. Perhaps even lexicographical comparison, if I'm dreaming.

Any thoughts on either of those?

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

#562

A couple of (I hope easy) requests - 1. Can we add separators in constants (C++ does 0xFFFF'FFFF'FFFF'FFFF any other reasonable scheme is fine too?) 2. I think many compilers already do this, but can the static initialization rules be relaxed a bit? static const int a = 0; static const int b = a; /* This is not standard C afaik. */ Thank you, CodeandC

A binary literal would be nice too. Doing masks for embedded systems makes my head hurt sometimes. "Cpp compatibility" etc etc could be the excuse to implement it.

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

#563
post #533

1. When will we get proper strings in the stdlib? 2. When we will get the Secure Annex K extensions? 3. When we will get mandatory warnings when the compiler decides to throw away statements it thinks it doesn't need? Like memset or assignments. Compilers are getting worse and worse, and certainly not better. ad 1) Strings are Unicode nowadays, not ASCII. Nobody uses wchar but Microsoft. Everybody else is using utf8,…

Going to try to answer these separately. For (1) if you mean strings that are primitive types my guess is never. When had an hour discussion on this topic at a London meeting where we were discussing new features for C11 and my take away was that this would never happen because it would require a significant change to the memory model for the language.

For the u8 type sure. Nobody needs a new type.

But at least add wcsnorm and wcsfc as I implemented them in the safeclib are required. Not even coreutils, grep, awk, ... can search unicode strings.

And u8 library variants of str* and wcs* are definitely needed, maybe just with uchar* not char*.

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

#564

A couple of (I hope easy) requests - 1. Can we add separators in constants (C++ does 0xFFFF'FFFF'FFFF'FFFF any other reasonable scheme is fine too?) 2. I think many compilers already do this, but can the static initialization rules be relaxed a bit? static const int a = 0; static const int b = a; /* This is not standard C afaik. */ Thank you, CodeandC

WG14 in general looks favorably at proposals to align C more closely with C++ (within the overall spirit of the language) and I'd expect (1) would viewed in that light.

I'd also say there is consensus that (2) would be beneficial. There are some good ideas in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2067.pdf although I don't think repurposing the register keyword for it was very popular. Not just because it wouldn't be compatible with C++ which deprecated register some time ago, but also because it's novel with no implementation or user experience behind it. My impression that this is waiting for a new proposal.

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

#565

The standard string library is still pretty bad. This would have been a much better addition for safe strcpy. Safe strcpy char *stecpy(char *d, const char *s, const char *e) { while (d Existing solutions are still error-prone, requiring continual recalculation of buffer len after each use in a long sequence, when the only thing that matters is where the buffer ends, which is effectively a constant across multiple cal…

What's wrong with:

    *p += sprintf(*p, "hello");
    *p += sprintf(*p, "world");

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

#566
post #403

C has been making strides towards complete Unicode support. I've been having trouble following along though: Am I correct in assuming that there's no actual multi-byte UTF-8 to UTF-32 Rune function and the best approximation depends on whatever wchar_t is? How would I best handle pure Unicode input and output scenarios on a "hostile" OS whose native character encoding is some EBCDIC abomination or a Windows codepage?

Probably link libicu rather than rely on libc.

libicu is a 40MB mess where you need only 5Kb of it. Only case folding and one normalization is needed, with tiny tables.

Additionally the used UNICODE_MAJOR and _MINOR are needed. They are always years behind, and you never know which tables versions are implemented.

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

#567
post #553

The standard string library is still pretty bad. This would have been a much better addition for safe strcpy. Safe strcpy char *stecpy(char *d, const char *s, const char *e) { while (d Existing solutions are still error-prone, requiring continual recalculation of buffer len after each use in a long sequence, when the only thing that matters is where the buffer ends, which is effectively a constant across multiple cal…

There are many improved versions of string APIs out there, too many in fact to choose from, and most suffer from one flaw or another, depending on one's point of view. Most of my recent proposals to incorporate some that do solve some of the most glaring problems and that have been widely available for a decade or more and are even parts of other standards (POSIX) have been rejected by the committee. I think only mem…

> Most of my recent proposals [...] have been rejected by the committee.

Does anyone have insight on why?

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

#568
post #352

Earlier quoted context omitted.

A good example might be 1's complement signed integers. They were dead weight in the standard for a long time.

Yes, but that is a slightly different question: how long you do you keep something in the standard after all the relevant hardware has disappeared, e.g,. is there a framework for periodically re-evaluating decisions in light of the changing hardware landscape. My question was more about when behavior is being defined for the first time, which admittedly doesn't happen that often (but it could apply e.g., when thing f…

Original standard feature specifications were not meant to obtain a 1-to-1 map from C onto hardware, but we used practical experience to judge what overhead was acceptable for the kinds of processors we had seen or thought were reasonable choices that the architects might make in the not too distant future. If a frequently-executed action had to (for example) check for a special condition every time, the overhead might increase by several percent, depending on the instruction set architecture. So quite often we argued that "if the programmer wants to test for that condition, he can do so, but typically it is a waste of cycles". There are a lot of such trade-offs; maybe we should write a paper or book on this topic.

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

#569
I think C is an exceptional good language for a long time, but the world is changing and maybe C must evolve with new trends, new researches in programming languages.

In my view C and C++ now almost different languages with a different philosophy of programming, different future, and different language design.

It will be sad if "modern" C++ almost replace C. Many C++ developers use "Orthodoxy C++" https://gist.github.com/bkaradzic/2e39896bc7d8c34e042b, and this shows that people will be more comfortable with C plus some really useful features(namespaces, generics, etc), but not modern C++. I very often hear from my job colleagues and from many other people who work with C++ is how terrible modern C++ (https://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/, https://www.youtube.com/watch?v=9-_TLTdLGtc) and haw will be good to see and use new C but with some extra features. Maybe time to start thinking about evolution C, for example:

  - Generics. Something like generics in Zig, Odin, Rust. etc.
  - AST Macros. For example Rust or Lisp macroses, etc.
  - Lambda
  - Defer statement
  - Namespaces
What do you think?

https://ziglang.org/documentation/master/#Generic-Data-Struc...

https://odin-lang.org/docs/overview/#parametric-polymorphism

https://doc.rust-lang.org/rust-by-example/generics.html

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

#570

1. How likely are named constants of any types to be included in C2x? I'm referring to the idea of making register const values be usable in constant expressions. 2. Is there, or was there ever a proposal to make struct types without a tag be structurally typed? This would not break backwards compatibility as far as I can see, and would make these types much more useful as ad-hoc bags of data. Small example: struct {…

I'd expect a proposal for (1) to be well received. The only proposal I recall that deals with (2) is http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2067.pdf. I think it's still being discussed. (3) is highly unlikely if it involved ABI changes. Even if it could be done without such changes unless there is a precedent for it in an existing compiler (and preferably more), it would likely be a tough sell.
Post reply on HN