HNHacker News
TopNewBestAskShowJobs

tom_mellior

4,934 karma · joined May 21, 2015

submissionscomments
tom_mellior··on Let's Build a Regex Engine (2019)
It hurts my eyes to see the author consistently misspell "automaton" as "automation".
tom_mellior··on The only Buddhist region in Europe
"Be nice to each other" is preached by every other world religion, as well as being at the center of many non-religious world views. The fact that we can and should be nice to each other to make the world a better place can hardly be what the grandparent meant by "knowledge to humans that is not knowable by any other means", which was what I was really asking about.

Thanks for your perspective. You're certainly selling it better than the Catholic Church is. (You won't be surprised to hear that I'm not buying into the whole thing either way.)

tom_mellior··on E-Prime – English without the verb “to be”
Interesting, thanks. It's true that "hot takes" of the form "X is Y" become a bit more difficult without the copula. Not sure how much we win by saying "A dictator rules Russia" vs. "Russia is ruled by a dictator", but I can see how just the fact of having to think more carefully about the formulation can contribute to a more reasoned discussion. It's a pity that the Wikipedia article fails to explain this point.
tom_mellior··on Servers as they should be – shipping early 2022
Something about this website takes my machine to 500% CPU load (Firefox/Linux). Good thing we will get 2048 cores soon...
tom_mellior··on The only Buddhist region in Europe
You're right that there is a well-established term "Southeast Europe" to refer to the countries you mention: https://en.wikipedia.org/wiki/Southeast_Europe

But there is also the fact that Europe continues far to the east of those parts, so there is another southeast corner somewhere else.

tom_mellior··on E-Prime – English without the verb “to be”
What about "to be" shows thinking that needs unmuddying? Why should we consider sentences like "the cat is an animal" or "the cat is furry" problematic?
tom_mellior··on The only Buddhist region in Europe
What knowledge would that be? At least in these Catholicism-dominated parts, that knowledge seems to look something like "you better watch it because you're a sinner and might end up burning in hell, except that Jesus saved you because he loves you, but for some reason despite being saved you are still a sinner and might end up burning in hell". You kind of sound like that's not the premise you mean.
tom_mellior··on The fastest and shortest algorithm for all well-defined problems (2002)
> This causes an interesting problem: how do we switch to the optimised version? JITs don't bother switching calls which are already running

Many JITs can do this. This is called "on-stack replacement" (OSR).

tom_mellior··on The fastest and shortest algorithm for all well-defined problems (2002)
OMG yes. The "gate" in its name is really apt. ResearchGate adds zero value but non-zero barriers to access.
tom_mellior··on Charlie Bit My Finger video to be taken off YouTube after selling for £500k
Ha! This is an excellent take. Maybe minus the "limited edition" part, since whoever minted the NFT can just mint the same one again. Even if they claimed they wouldn't.
tom_mellior··on Ask HN: What kind of chair are you using for WFH?
I have a sit/stand desk that I bought expecting to stand the first half of the day, then sit the second half. On the very first day I forgot to ever sit down, and I've been 100% standing ever since. I stand on a rubber mat thing with some bumps and raised edges that makes it enjoyable to switch stances. But I've always been someone who fidgets a lot, and I tended to constantly reposition myself on office chairs too. Like others, I also suggest walking around often, whether sitting or standing. Drinking a lot of water and having a very small bladder definitely helps.

All that said, while I recommend trying a standing setup if you can, it's definitely not for everyone. My partner has tried my desk several times and always became infuriated at the concept of standing while working.

tom_mellior··on Undefined behavior in C is a reading error
> A lot of C optimization could work that way - relying on cooperation between the compiler and programmers.

That is precisely how it works already. The reason your code has no bounds checks is exactly because the compiler can assume that you have done your part and ensured that all indices are in bounds. This is what "the compiler can ignore UB" is all about.

The signed integer kerfuffle is just the same: The compiler assumes your cooperation in ensuring, beforehand, that your signed arithmetic never overflows. Its part of the bargain is generating the best possible code it can. Another part of its bargain is offering you the -fwrapv flag to communicate more about your expectations. A third part of the bargain is offering you sanitizers that can inform you that you have done something you probably didn't want.

tom_mellior··on Undefined behavior in C is a reading error
So on the one hand you're (rightly) saying that this function has no semantics under the rules of the C language, but on the other hand you're saying that the semantics that C compilers assign to it is a bug, and on the third hand you are saying that the hardware should assign semantics to it even though this code is not written in assembly language, so it's not clear what the hardware should assign semantics to? Got it.
tom_mellior··on Undefined behavior in C is a reading error
Nice. If you like, could you explain again what the perceived difference is to adding

    if (offset >= INT_MAX - 16) fail();
in foo()?

(I mean, besides the fact that the size of the buffer pointed to by arr is highly unlikely to agree exactly with either INT_MAX or UNIT_MAX.)

tom_mellior··on Undefined behavior in C is a reading error
>> an uninitialized y is an actual uninitialized register or memory location.

> On typical hardware, yes.

Maybe you can help me identify the register or memory location for y in your example: https://gcc.godbolt.org/z/3b4z56Y87

tom_mellior··on Undefined behavior in C is a reading error
But you're not using the offset to compute the index in bar().

    void foo(int offset, int *arr) {
        for(int i = offset; i < (offset + 16); i++) {
            arr[i] = i + 32;
        }
    }
If you call this with offset = 100, the arr[i] in the loop will write to arr[100], arr[101], ..., arr[115].

    void bar(unsigned int offset, int *arr) {
        if(offset+16 < offset)fail();
        for(size_t i = 0; i < 16; i++) {
            arr[i] = i+ offset + 32;
        }
    }
If you call this with offset = 100, the arr[i] in the loop will write to arr[0], arr[1], ..., arr[15].
tom_mellior··on Undefined behavior in C is a reading error
> This is permissible (on typical hardware)

Hardware doesn't define C semantics. C defines C semantics. I don't understand what your conditional example is trying to say, but you seem to assume that an uninitialized y is an actual uninitialized register or memory location. It's not.

>> A function marked _Noreturn returns.

> If written in C, the body of the function must include a return statement, and is thus a compile time error.

It might contain a return statement that is never reached because the function goes into an infinite loop or exits/aborts the program or does a longjmp.

tom_mellior··on Undefined behavior in C is a reading error
You changed writes to indices offset..offset+15 to writes to indices 0..15.
tom_mellior··on Undefined behavior in C is a reading error
Yes, with lots of extra ceremony around it. (More than is needed, since it doesn't seem to realize that it will always process exactly 16 loop iterations.)

Since you've posted a lot along the lines of "these optimizations don't even make a difference", you might want to see if Clang's safer-looking version is as fast as GCC's.

tom_mellior··on Undefined behavior in C is a reading error
I think you are misunderstanding the situation. Given code like:

    if (!p) {
        use(*p);
    }
(given no previous knowledge about p) no compiler will remove the "if (!p)" part.

What people are complaining about is the opposite case:

    use(*p);

    /* The compiler reasons that if p == NULL, the program would have crashed by now,
       so if we got here, p != NULL must hold. */

    if (!p) {  // the compiler can remove this branch
        report_error();
    }
tom_mellior··on Undefined behavior in C is a reading error
Could you post a complete example please and tell us which compiler optimizes out this check? Clang and GCC don't: https://gcc.godbolt.org/z/dbTadEcra
tom_mellior··on Undefined behavior in C is a reading error
In all of the examples above it will emit a machine instruction to dereference p. What your grandparent is complaining about is that it will later remove an "if (!p)" test.
tom_mellior··on Undefined behavior in C is a reading error
> The trouble was that in that context, a null pointer dereference didn't trap, (because it was kernel code? not sure.) so the bug was not detected.

Yes, because it was kernel code. Because that dereference is completely legal in kernel code. The C code was fine, assuming that it was compiled with appropriate kernel flags. This was not a bug in Linux, at least not on the level of the C code itself.

> The linux kernel now uses -fno-delete-null-pointer-checks to ensure that doesn't happen again.

I also seem to remember that it was already using other "please compile this as kernel code" flags that should have implied "no-delete-null-pointer-checks" behavior, and that the lack of this implication was considered a bug in GCC and fixed.

tom_mellior··on Undefined behavior in C is a reading error
> The proper way for a compiler to handle this, would be to add a single overflow check before the loop, which branches to a scalar translation of the loop. Most realistic code will need a scalar version anyway, to deal with the prolog/epilog of the unrolled loop for iteration counts that aren't multiples of the unrolling factor.

That's true, I agree that that would be a clever way to handle this particular case. It would still happily invoke undefined behavior if the indices don't match the array's length, of course. Many assumptions about the programmer knowing what they are doing goes into the optimization of C code.

> Surely you agree that treating unsigned overflow differently from signed does not make any sense semantically?

Yes. Silently wrapping unsigned overflow is also very often semantically meaningless.

tom_mellior··on Undefined behavior in C is a reading error
This was in the Linux kernel, which is compiled with special kernel flags which make dereferencing null pointers legal. In the context of that code, dereferencing a pointer and later checking it for null was absoutely meaningful. Optimizing the later null check was a compiler bug that was acknowledged and fixed. The compiler here didn't respect the semantics it had promised to kernel code. This was entirely uncontroversial; it was not a case of "unwanted optimization based on undefined behavior", it was a case of "compiler bug breaking well-defined code". Again, all this in a kernel context.

In user code GCC will still happily remove the null check because in user code this is an actual bug in the user's code.

tom_mellior··on Undefined behavior in C is a reading error
If you want pragmatism, check whether something is legal before you do it.
tom_mellior··on Undefined behavior in C is a reading error
The world doesn't end, but in the "int" case you get nice vector code and in the "unsigned int" case you get much less nice scalar code: https://gcc.godbolt.org/z/cje6naYP4
tom_mellior··on Undefined behavior in C is a reading error
> In my mind it's 100% not okay to (by default) optimize away a check for integer overflow.

But a + 100 > a is not a check for overflow. If a >= INT_MAX - 100, it is an overflow. The "will this operation overflow" check would be a >= INT_MAX - 100, and GCC would not optimize that away.

tom_mellior··on Undefined behavior in C is a reading error
I'm not convinced. The argument seems to hinge to a very large extent on the sentence:

> Permissible undefined behavior ranges from A, to B, to C.

The observation that "Permissible" has a specific meaning is important and interesting. But what about "ranges from ... to ..."? The author reads this as "Permissible undefined behavior is either A or B or C.", but that seems like a stretch to me. (Unless ISO defines "ranges" to mean just this.)

Also, in the above, A = "ignoring the situation completely with unpredictable results". Both "ignoring" and "unpredictable" do a lot of heavy lifting here. In the signed integer overflow case discussed in the linked GCC bug report (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475), one could very well argue that "ignoring" a case where signed arithmetic overflows is exactly GCC is doing. It "ignores" the possibility that a + 100 might overflow, hence obviously a + 100 > a is true, leading to results that the reporter considers "unpredictable". Somehow the author seems to think that this is not what the wording intended, but they also fail to explain what they think should happen here.

Sounds to me like the wording has always been very vague.

Also:

> Returning a pointer to indeterminate value data, surely a “use”, is not undefined behavior because the standard mandates that malloc will do that.

Yes, malloc will do that, but using a pointer to indeterminate data is not the same as using the indeterminate data itself. The author is doing themselves a disservice by misreading this.

tom_mellior··on Undefined behavior in C is a reading error
> The C standards have the perfectly fine name "implementation dependent" to describe those things.

That term is not used by the C standards. Do you mean "implementation-defined"? asm is not among the explicitly specified implementation-defined behaviors, it's listed under "Common extensions". I don't see any mention at all of syscalls in C99. (I'm working with http://www.dragonwins.com/courses/ECE1021/STATIC/REFERENCES/... here.)

← PreviousPage 2 of 34Next →