1,545 karma · joined Aug 14, 2022 (4y ago) · 937 submissions
comment 1mo ago · link · parent
> C11 is last C as far as I'm concerned.
Are you sure? I think C23 brought so many enhancements it's a pity to ignore it.
comment 2mo ago · link · parent
Because it sells well? Because it's what a significant portion of people want?
> Its pretty obvious where the future is headed for personal vehicles
"Where", yes. "When" is a big question mark. If the transition will take several years to complete, which many bet it will, it makes perfectly sense to offer a car that people is willing to buy in the meanwhile.
The Chinese brands that you mention also offer hybrids: indeed most BYDs I see in the streets have the "DMi" tag, which is BYD's codename for hybrid. And they are investing in fuel engines, too. Only short-sighted euro burocrats think that since EV are the future we should immediately stop selling and innovating fuel cars.
comment 2mo ago · link · parent
comment 2mo ago · link · parent
I'm the author of the example. I wanted to keep it as simple as possible, and this is the most common form of for loop. I was sure that HN readers would be clever enough to "map" it to whatever they have in their mind that satisfy the undecidability of the condition.
But since you're nitpicking, I haven't specified the types of i and n: i is uint8_t and n is uint32_t. Does it terminate? It depends on the value of n!
comment 2mo ago · link · parent
Forget if "i<n" is decidable or not: the sense is that there will always be some loops that the compiler can't determine if it's finite or not.
Forget if A and B can alias or not: the sense is having two independent actions that can be executed in the same loop or in two consecutive loops.
Let's see... what about the following example, that replaces all a's with @ and all e's with & in a zero-terminated string s?
for (char *p=s; *p; p++)
if (*p=='a')
*p='@';
for (char *p=s; *p; p++)
if (*p=='e')
*p='&';
If a compiler is allowed to assume that the first loop terminates, then it may optimize it to: for (char *p=s; *p; p++) {
if (*p=='a')
*p='@';
if (*p=='e')
*p='&';
}
Is this explanation less insane?comment 2mo ago · link · parent
Because you explicitly mentioned details that belong in the implementation, not in the semantic:
> A halt/abort instruction that trashes [the] state would be undesirable
If you want to attach a debugger, then use a breakpoint, don't try to obtain the same effect within the code.
comment 2mo ago · link · parent
for (i=0;i<n;i++)
A[i]=0;
for (i=0;i<n;i++)
B[i]=0;
It can be conveniently transformed into this: for (i=0;i<n;i++)
A[i]=B[i]=0;
They are exactly equivalent except if the first loop never terminates.Now, the compiler could try to understand if the first loop does or doesn't terminate, and apply or not the optimization accordingly, but Turing tought us that is indeed a hard task!
Or it could decide to never apply it, for fear of those rare and usually pathological cases where the first loop doesn't terminate.
Or it could decide to apply it by default and accept that in those cases the program does something different than what the source code says. The latter is better known as UB.
The third option won, and that's why infinite loops are UB in the standard.
comment 2mo ago · link · parent
If you write a loop to zero out some memory, it can be compiled to a loop, or to a call to an optimized predefined function, or even to a sequence of single zeroing instructions, if the size is small enough.
Even a single statement as a=0 may be compiled to a "load immediate" instruction, or an "XOR with itself", or a "sub with itself", or a move from another register known to be 0.
comment 3mo ago · link · parent
Not at all. Contrary to other games where undos are cheating, here they are part of the game. Without them it would be 80% luck and only 20% strategy.
> which is heavily implied
I can't find anything that implies this. It explicitly says:
> This uses undos deliberately rather than only as an emergency
while avoiding undos is mentioned at the end as "The Purist approach", which I read as slightly mocking.
I see it like a chess problem where you have to find the best sequence of moves, so you start off with an intial move, then backtrack, explore another idea, etc. Not like a chess match where of course you cannot undo any move.
comment 3mo ago · link · parent
Imagine it like someone suggesting (understandably) that you express memory sizes in hex: no push to make everybody stop using decimal numbers!