Recent submissions

Comment · 24 days ago
I disagree, though I wouldn't mind adding a mechanism to say that you want signed overflow to be well defined.

C23 already requires 2's-complement representation for signed integer types, but signed overflow still has undefined behavior. I think that mandating 2's-complement wraparound would be a mistake.

Some instances of undefined behavior can be detected at compile time. For example, if I write

    int too_big = INT_MAX + 1;
a reasonably clever compiler can warn about it (and in fact both gcc and clang do so). If the result of INT_MAX + 1 were defined by the language to be INT_MIN, there would be no basis for such a warning.

If you evaluate n + 1 and it's possible for n to be equal to INT_MAX before the addition what do you want the result to be? Would quietly yielding INT_MIN really be useful?

Ideally, if I (accidentally) evaluate INT_MAX + 1, I'd like to be told that I've made a mistake. C doesn't have a good mechanism for doing so.

gcc has a non-standard option "-fsanitize=signed-integer-overflow" that can be used to catch signed overflow at runtime. If signed overflow yielded a well defined result, that option would be non-conforming.

Comment · 1 month ago
Comment · 2 months ago
And if a button has appeared on the screen in the last half second or so, assume that any attempt to click it was unintentional (unless it appeared due to an explicit action by the user).

Similarly, if a button has recently moved, wait a little while before activating it. (Better yet, arrange for things not to move around as the page is loading.)

Comment · 2 months ago
Does that really mean that the day after 24 March 1750 was 25 March 1751?
Comment · 3 months ago
The image shows the `eval` on the same line as the `#!/bin/bash`.

It should be on a separate line.

    #!/bin/bash eval "$(base64 -d <<< '...
Comment · 4 months ago
Comment · 4 months ago
Comment · 4 months ago
Strictly speaking it's the ISO C standard. ISO issues each new edition of the standard, and ANSI adopts it.

This was reversed for the first standard, which ANSI published in 1989; ISO adopted it, with editorial changes, in 1990. The term "ANSI C" usually (not entirely correctly) refers to the 1989 standard. If you want to refer to a particular version, it's best to refer to "ISO C" and the date (1990, 1999, 2011, 2023).

The money you pay for a copy of the standard doesn't go to the people who do the work of writing it, who are either volunteers or paid by their employers.

Comment · 4 months ago
They hadn't yet decided whether to count from 0 or from 1.
Comment · 4 months ago
I wonder if the book itself is actually any good.

My understanding is that authors often have little or not control over the covers chosen by their publishers.

It's at least possible that the book itself is excellent, but I'm not going to spend $90+ on a hardcover copy to find out.

Comment · 5 months ago
No, the behavior is undefined. That means, quoting the ISO C standard, "behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this document imposes no requirements".

A conforming implementation could reject it at compile time, or generate code that traps, or generate code that set a to 137, or, in principle, generate code that reformats your hard drive. Some of these behaviors are unlikely, but none are forbidden by the language standard.

Comment · 5 months ago
If the behavior is undefined, there is no wrong result.
Comment · 5 months ago
Are you volunteering to update all the code that would be broken?
Comment · 5 months ago
Your code:

    int a = 5;
    int b = a++;
has well defined behavior. The first line initializes a to 5. The second initializes b to 5 and sets a to 6. (The language doesn't specify the order of the two operations of assigning a value to be and incrementing a, but in this case it doesn't matter.)

Giving 13 for a++ + ++a is not a bug in the compiler. It's a bug in the code.

The correct answer to "what does a++ + ++a do" is "it gets rejected in code review and replaced with code that expresses the actual intent.

Comment · 5 months ago
"Test Your C Skills" is a published book by Yashavant Kanetkar, apparently published in 2005, and still available in paperback. The document you linked to appears to be a scan of a printed copy of that book, and is almost certainly in violation of copyright. The cover and the title and copyright pages are notably missing.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton