• 24 Posts
  • 43 Comments
Joined 2 months ago
cake
Cake day: August 9th, 2026

help-circle
  • I’m surprised that the list of issues does not include the implicit narrowing conversion from the string size to an int. (Especially since the list does complain about the implicit widening conversion in the str[] indexing expressions.)

    int size = str.size();
    

    Integer conversions need a great deal of care in C and C++ so this was the first thing that caught my attention. They had a lucky escape from UB in this case since narrowing conversions are implementation-defined, and an overflow to a negative index is caught by the loop guard (because it’s designed to cope with deliberate underflow due to an empty string). But the algorithm is quietly wrong for strings longer than INT_MAX.

    I’d rephrase the title to, The problem with C++ safety: “it works” is often undermined by the language.


    score 1 · canonical





  • I haven’t been paying close attention to this story in the last year or two, so it’s a surprise that the change is happening sooner than expected (tho it wouldn’t have been a surprise if I had looked at the meeting agenda):

    • continuous UTC will become effective on 20 May 2027,
    • the maximum value for the difference |UT1-UTC| will be 3 600 seconds (1 hour), ensuring the long term continuity for UTC for several centuries,

    The provisional plan agreed at previous treaty conferences (GCPM and WRC) was to make the change in 2035, but the prospect of a negative leap second encouraged them to make the change sooner.

    However it seems that the near-term likelihood of negative leap second has become much lower this year. If you look at the earth orientation parameters finals.data (IAU2000) plots observe:

    • the slope of UT1-UTC seems to be returning to normal, and (equivalently) the length-of-day is roughly trending slightly over 24h instead of slightly under
    • the mysterious change in behaviour of the dX and dY charts that matches the change in slope of UT1-UTC seems to have reverted as well

    It’s hard to be sure if earth rotation is really back to its pre-2020 behaviour, because much of the change that I’m observing is in the blue prediction section of the charts.


    score 1 · canonical










  • I checked what IEEE 754 says, and I was surprised! I wonder if any languages do what it specifies.

    The 2008 and 2019 editions have the following paragraph. The 1984 edition has the same effect but not so clearly set out in one place.

    When a NaN or infinite operand cannot be represented in the destination format and this cannot otherwise be indicated, the invalid operation exception shall be signaled. When a numeric operand would convert to an integer outside the range of the destination format, the invalid operation exception shall be signaled if this situation cannot otherwise be indicated.

    Java and Rust specify NaN converts to 0 and overflow saturates when these situations cannot otherwise be indicated.

    More entertainingly,

    A language standard that permits implicit conversions or expressions involving mixed types should require that these be implemented with the inexact-signaling conversion operations below.

    I tend to think that when a specification has a “should”, it needs a clear discussion of the considerations for when an implementation can disregard the “should”. Even more so when the “should” is widely ignored by existing implementations, in which case the rationale needs an honest explanation of why the spec and the implementations diverge.


    score 2 · canonical












  • The right answer should be memset_explicit(). I was disappointed that this article never mentioned the Standard solution to this issue, or pre-standard versions such as explicit_bzero(). But I don’t think that omission makes much difference because clang and gcc don’t seem to know enough about memset_explicit() to avoid a spill to memory.

    Unfortunately memset_s() is entangled with the Annex K portability problems and its crazy runtime constraint checking and exception handling, which makes it hard for compilers to implement memset_s() as a sensible builtin.

    The special case for for memset_s() is:

    Unlike memset, any call to the memset_s function shall be evaluated strictly according to the rules of the abstract machine as described in 5.1.2.4. That is, any call to the memset_s function shall assume that the memory indicated by s and n may be accessible in the future and thus contains the values indicated by c.

    And for memset_explicit():

    The purpose of this function is to make sensitive information stored in the object inaccessible. (footnote: The intention is that the memory store is always performed (i.e. never elided), regardless of optimizations. This is in contrast to calls to the memset function (7.26.6.1).)


    score 1 · canonical



  • Footnotes are always a mandatory disruption to the flow of reading, because readers can’t tell up front whether a footnote is worth the effort or not. Like when reading on paper, a footnote should always be in view and never require interaction, so it can be read with just a glance. Which implies that on a web page it’s better to lay out that kind of thing as an aside, without trying to emulate paper footnotes.

    “Footnotes” on web pages are more like endnotes in books, where you have to keep an extra finger between the pages and repeatedly flip back and forth. (Even worse if the endnotes are used for both citations and commentary!)


    score 1 · canonical