News for hackers. Stuff that matters.
Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @04:23AM (#30395655)
So true and false keywords are the only thing that has been added, or am I missing a part of this thread?

Edit: I think one of these could be a better link: https://en.cppreference.com/w/c/23 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2864.pdf

Re:C meeting is over. C23 added: by fulafel on Saturday February 19, 2022 @04:59AM (#30395833)
The cppreference.com link says it removes "Representations for signed integers other than two's complement" - this could be pretty significant in making many previously implementation-defined programming patterns strictly conforming, but is it true? Doesn't seem mentioned in the Twitter thread.
Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @05:38AM (#30396032)
This is the accepted twos complement proposal: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2412.pdf

It seems like a sensible simplification to me. Is there any architecture that doesn't use twos complement (eg. uses separate sign bit + magnitude) and could run C code?

Re:C meeting is over. C23 added: by MaxBarraclough on Saturday February 19, 2022 @06:59AM (#30396455)
> Is there any architecture that doesn't use twos complement (eg. uses separate sign bit + magnitude) and could run C code?

I think such machines are pretty much a thing of the past. This topic cropped up in a 2018 thread when C++ made the same change. [0]

[0] https://news.ycombinator.com/item?id=17190864

Re:C meeting is over. C23 added: by Findecanor on Saturday February 19, 2022 @03:09PM (#30400065)
The devil is not in the number representation but in the details. The proposal says:

> Overflowing operations and out-of-range conversion are generally mapped to modulo operations and cannot trap or raise signals.

This would be a problem on x86, where INT_MIN / -1 causes a #DE (divide error) exception. In C17 that is fine because signed integer overflow is undefined behaviour. But if the behaviour is defined, that trap would have to be caught or avoided.

The best solution for performance would be to have a new trap handler. That would have to parse the instruction to find its length, and the divisor (in memory or register) to differentiate it from division by zero, write the constant result and remainder into the destination registers (always rax and rdx thankfully) and then continue with the next instruction.

But I think this could be difficult to do in a fool-proof way, with how CPU exceptions are handled in different operating systems. Some operating systems might not even allow it at all.

Re:C meeting is over. C23 added: by pascal_cuoq on Saturday February 19, 2022 @05:09PM (#30400986)
The sentence you quote is near to the words:

“[The C++ standardization committee] WG21 has recently adapted the changes promoted in their document p12363. Generally, C++ goes much beyond what is presented here:”

I would be extremely surprised if the proposal to make signed arithmetic overflow defined behavior in C made it into C23. The window is narrowing and this would be a very big change to the language. Making it official that 2's complement is the only representation for signed integers is already a large change.

Later in the decade, maybe.

Re:C meeting is over. C23 added: by qsort on Saturday February 19, 2022 @06:55AM (#30396438)
Some microcontrollers used to have saturating arithmetic, which is basically the only other behavior that makes any sense.
Re:C meeting is over. C23 added: by MaxBarraclough on Saturday February 19, 2022 @07:00AM (#30396464)
Perhaps I'm missing something obvious, but isn't that orthogonal to representation? You could implement saturating arithmetic for any representation scheme, no?
Re:C meeting is over. C23 added: by tomsmeding on Saturday February 19, 2022 @09:14AM (#30397260)
You can only observe whether the representation is 2s-complement or not if you can see what wrapping does.
Re:C meeting is over. C23 added: by MaxBarraclough on Saturday February 19, 2022 @09:25AM (#30397340)
That doesn't sound right. You can use the union trick in C (but not C++, strictly speaking) to read the bit-pattern of a signed integer as an unsigned integer, for example. [0]

Overflow of signed integer types remains undefined behaviour in both C and C++. A compiler is free to make a promise like signed integer overflow is always handled with wrapping or signed integer overflow is always handled with saturation. (GCC has a flag, -fwrapv, to enable guaranteed wrapping. [1])

[0] https://stackoverflow.com/a/25664954/

[1] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html

Re:C meeting is over. C23 added: by gallier2 on Sunday February 20, 2022 @09:22AM (#30405904)
The AGC (Apollo Guidance Computer). This means we won't go to the moon anytime soon ;-)
Re:C meeting is over. C23 added: by NotSoVeteran on Saturday February 19, 2022 @04:28AM (#30395677)
The linked tweet is the 4th in a sequence. If you scroll up you should see 3 more tweets with more info.
Re:C meeting is over. C23 added: by rwmj on Saturday February 19, 2022 @04:31AM (#30395687)
Thanks - Twitter UI is terrible.

I'm glad the terrible "defer" suggestion didn't make it, but unfortunate that they didn't standardise the existing and widely used attribute cleanup.

Re:C meeting is over. C23 added: by wartijn_ on Saturday February 19, 2022 @06:08AM (#30396188)
This is off topic, but I don't think the problem is just that the Twitter is terrible.

If you want to link to a thread, you should click on the first tweet of that thread and copy its url. It's easy to see the rest of the thread: just scroll down.

If you want to link to one tweet in a thread you should click on that tweet and copy its url.

The person who posted the link to HN did the latter, while they should have done the former.

Twitter could make it easier to see that a tweet is part of a thread though.

Re:C meeting is over. C23 added: by notreallyserio on Saturday February 19, 2022 @11:06AM (#30398098)
While we're off topic here's my little rant about Twitter "threads":

It's easy to see all of the tweets made by the author, at least those made as replies to themselves, but reading the actual threads is hard or impossible. At least I haven't figured out how to do it despite considerable effort.

For example, say you want to view the replies to the tweet above the linked tweet, the one about "assert". There are supposedly 4 replies. If you tap that tweet you remain in the same list of self-replied tweets. There are replies at the end, but are they replies to the tweet you want to focus on? It doesn't look like it, but who knows, maybe? It's even worse on linger Twitter self-reply "threads".

I don't know how Twitter's engineers got the well-established threading pattern so wrong. This behavior doesn't even increase the number of ads you see.

Re:C meeting is over. C23 added: by secondcoming on Saturday February 19, 2022 @08:55AM (#30397139)
Twitter is bad if you don't have a twitter account. It'd be great if HN could change twitter links to go through nitter.net
Re:C meeting is over. C23 added: by buserror on Monday February 21, 2022 @06:09AM (#30414387)
I'm the one who pointed attribute cleanup to them tho (on twitter no less) -- apparently they weren't aware of it... ? https://twitter.com/BusError/status/1481706530831585284
Re:C meeting is over. C23 added: by ksec on Saturday February 19, 2022 @09:01AM (#30397169)
I was so sure I copied the first tweet to submit. That is why the title is the same as the first tweet. Somehow I messed it up. May be Dang could change it to

https://twitter.com/__phantomderp/status/1494801365297676293

Re:C meeting is over. C23 added: by kevin_thibedeau on Saturday February 19, 2022 @04:55AM (#30395813)
They're still macros. C will never add new keywords outside the reserved namespace.
Re:C meeting is over. C23 added: by duskwuff on Saturday February 19, 2022 @05:27PM (#30401114)