by MisterTea · 1mo ago · 0 comments
I have a friend who is currently on the C committee and is likely going to leave because of all the bad ideas which have both been implemented and going to be implemented.
* No, spamming a million ugly #ifdefs all over the source files is gross and hard to read. Split up the code dammit.
(D sez `char` is unsigned. No more nonsense!)
C also needs to implement proper arrays. D does it, and that one feature is worth its weight in gold:
https://www.digitalmars.com/articles/C-biggest-mistake.html
It's sooo nice to not have array overflows anymore.
i'm old school. ascii is 7 bits, if you're using the 8th bit you probably want a sign since you've left the realm of ascii chars
Not that I disagree with making basic types unsigned by default, just not in C.
char - unsigned 8 bits
byte - signed 8 bits
ubyte - unsigned 8 bits
char is used for utf-8, byte and ubyte are signed and unsigned small integers. This seems like small thing, but it makes D code much more readable than C.I bet a lot of existing C code will break if one sets char to signed with a compiler switch.
Anybody reviewing C code and sees just char will have to waste time wondering if the code handles the implementation-defined signed-ness correctly.
And yes, I know about stdint.h, a poor attempt to deal with this problem.
* thread_local and _Atomic support from C11
* fopen("foo", "x") from C11
* aligned_alloc from C11
* CMPLX macro from C11
* C++ attribute syntax ([[foo]] flows better to me than __attribute__((foo)) does)
* C23 finally gets rid of _Who _The _Hell _Thinks _Users _Like _This-style _Keywords.
* Multi-level break/continue in C2y
* Variable declarations in if conditions.
* Some of the new operations like ckd_add or stdc_rotate_left. I do dislike the names, but meh, at least C is starting to gain a competent set of fundamental operations.
Also, I'm personally still waiting for a "shift left" operator having cleaner wording in the standard:
If E1 has an unsigned type, the value of the result is E1 × 2**E2, wrapped
around. If E1 has a signed type and nonnegative value, and E1 × 2**E2 is
representable in the result type, then that is the resulting value; otherwise,
the behavior is undefined.
What does "otherwise" means here? It can't mean "if E1 has an unsigned type, or negative value, or E1 × 2**E2 is unrepresentable, then the behavior is undefined" because the part "if E1 has an unsigned type" has already been covered by the previous clause. Does it mean "If E1 has negative value, or E1 × 2**E2 is unrepresentable, then the behavior is undefined"? Because that's a ridiculous ordinance: (-1) << 1 is UB?!That's exactly what it means, see the change mentioned in https://www.open-std.org/jtc1/sc22/wg14/www/docs/n723.htm. (Previously, in C89, left shift on signed integers was completely undefined, only unsigned integers had a defined left-shift operation.) My guess is that it has to do with signed-magnitude representation causing left shifts to be absolute garbage with negative numbers. You also have to remember that the standard having undefined behavior doesn't preclude implementations from defining that behavior, and this is especially true with the freewheeling nature of a lot of the original undefined behavior introduced in C89 and C99.
> Also, C23 (and C2y) is moving ever closer to actually having defined semantics.
Eh, having seen how some of the sausage gets made, there's definitely been some cases where the overeager urge to rip out undefined behavior from the standard has worsened the quality.
No, it was implementation defined, which is very different. Every implementation you were ever likely to encounter defined it reasonably. Making some of it undefined now has created a bunch of code that uses macros to cast back and forth between unsigned to get the expected behavior (or, for cases where it is provable that the result is representable, to replace the left shift with a multiplication and hope the optimizing compiler translates it back, because compilers now warn on any left shift of a negative value, despite the fact that the semantics are supposed to be the same as the corresponding multiplication now).
In other words, it created a mess for basically no reason.
I guess I can understand that signed shifts bump up against how the hardware represents signed numbers at the bit level, but it’s not like the assembly is unclear on any given platform.
First of all, why not make it implementation-defined? That seems rather more useful for the programmer. Second, I'm personally aware of only a single machine with signed-magnitude representation, IBM 7090, and its ALS (Accumulator Left Shift) instruction treated the sign bit as sticky; amusingly, LGL (Logical Shift Left) did as well, so you had to put the value being shifted into the MQ register, not the accumulator, when you wanted an unsigned shift. So... no, that can't be it?
I also do not see where the quality suffered. There were some rather minor issues we created and need to cleaned up.
Shifting into the sign bit is also UB. Can I please have a language that actually has bitwise operators with defined semantics? No CPUs had differentiated between SAL/SHL for more than 30 years, if that was the original justification.
I'm fine with left shift trapping on overflow. I'm fine with it just wrapping around. I'm even fine with bitwise shifts simply unapplicable to ints ("cast to unsigned first, then cast back to int"). I am not fine with an operator that invokes UB for literally half of the values of the lhs's domains.
I always took those to mean "we're sure a bunch of you are already using the keyword we wanted to use as typedef in your codebase, so here's something that's in the standard's namespace, and you can typedef it to something sane for your codebase".
C23 broke a lot of code by making this proper lower case keywords, we probably should have waited longer.
Bounded checked slices like proposed by Dennis Ritchie, or Walter Bright, remains a pipe dream.
_Generic isn't generics/templates
it is function overload
Atomics are necessary nowadays though.
Not that I'd want it, I like complex type systems, but I see it as philosophically consistent with C.
It's not just about atomics, but you might still find Hans Boehm's 2005 paper "Threads Cannot Be Implemented As a Library" [0] interesting. It describes (among other things) correctness and performance issues that can arise if the compiler and/or language don't know about thread/atomic semantics.
[0]: https://web.stanford.edu/class/archive/cs/cs240/cs240.1236/o...
> We explicitly do not address the less frequently used environments in which multiple concurrent threads communicate communicate primarily through message passing, such as C programs communicating only through the MPI[34] library, or Erlang[11] or Concurrent ML[28] programs.
Heh, there's your answer. CSP FTW!
And, FWIW, in a lot of high-performance code, the overhead of a function call may be too high for an atomic operation.
What software do you write?
In what concerns C itself, as the language authors, they did not care that much about the standard, hence why it is mostly C89 with Rob Pike ideas on how header files should be organised, and other Plan 9 specific idioms.
I don't really mind though as it seems the far away real future is something like everything RISC-V assembly, "C" would only be the binary specification.
And some python/javascript/etc interpreters written in RISC-V assembly themselves, because sometimes my code can be slow and non-rigorous.
I'm not critical about languages evolving.. just the tech changes so quickly that perhaps standardising it doesn't make any sense any more.
I wonder if languages like RUST or GO will ever become ISO standards.. I do believe all these new platforms won't even get close to that need.
> I wonder if languages like RUST or GO will ever become ISO standards..
I doubt it, but mostly because everyone I know on the ISO standardization committees have expressed frustration with ISO (the organization) in ways that I haven't seen for other standards bodies like Ecma.
Haven't travelled much around Europe in the last decades, or had to deal with electricity projects, I gather.
Nowadays, due to the ways of ISO most languages end up going with ECMA, as ISO processes are considered somehow Jurassic.
However a resurgence in cold war like state of the world might indeed, bring us back to ISO as main driver for standardising languages instead of ECMA or open source, due to the way it ensures specifications and implementations aren't tainted by foreign politics.
Spoken like someone who's never felt the frustration of having a grounded plug and the only available sockets being two-prong.