Array member-initializers in GCC

The other day I ran across some code like this:

template<class T>
struct Holder {
  T t_;
  explicit Holder() : t_() {}
  Holder(const Holder& rhs) : t_(rhs.t_) {}
  ~~~~
};

This was in an old codebase, which until recently had still been using GCC’s -Weffc++ to enforce C++98 idioms such as the explicitly non-defaulted copy constructor depicted above.

If you’re still using -Weffc++, please, stop using it!

Read More

Wordle-like games require two word lists

Suppose you’re implementing a “Wordle-like” game such as Juho Snellman’s Huewords or Alan Bellows’ Omiword. The defining principle of such games (as I’m defining them here, anyway!) is that the solution to the puzzle is an arrangement of English words which satisfies some criterion, and the player arrives at that solution by guessing various English words, such that the game must differentiate “that’s a valid word, but not the answer” from “that sequence of letters isn’t even a word.”

Read More

Phrase origin: Why do we “call” functions?

On StackExchange, someone asks why programmers talk about “calling” a function. Several possible allusions spring to mind:

  • Calling a function is like calling on a friend — we go, we stay a while, we come back.
  • Calling a function is like calling for a servant — a summoning to perform a task.
  • Calling a function is like making a phone call — we ask a question and get an answer from outside ourselves.

The true answer seems to be the middle one — “calling” as in “calling up, summoning” — but indirectly, originating in the notion of “calling for” a subroutine out of a library of subroutines in the same way that we’d “call for” a book out of a closed-stack library of books.

Read More

Constexpr factors_of

I’m just now getting around to blogging this snippet from March 2024 (hat tip to Chip Hogg). Apparently some units libraries — things like Au and mp-units — find it useful to represent linear combinations of units as the products of primes; for example, if you represent “meters” as 2 and “seconds” as 5, then “meter-seconds” is 10. Or at least that’s the general idea, I think. Don’t quote me on that part.

This means there’s a market for fast compile-time versions of the functions next_prime_after(p) and prime_factors_of(c). Chip even went so far as to propose that vendors should provide “largest prime factor of c” as a builtin; see P3133 “Fast first-factor finding function” (February 2024). I said, “You don’t need the vendor to do your factoring; you can write that in general-purpose C++ already!”

Read More

NYPL Musical of the Month

Today I learned that the New York Public Library has a blog, on which, many years ago, curator Douglas Reside had a “Musical of the Month” series where he posted old libretti, recordings, and other paraphernalia. Sadly the NYPL’s current website design lacks any coherent indexing or tagging system: no full-text search, no search by author, etc. So, for my own benefit and the benefit of posterity, here are direct links to all of the NYPL “Musical of the Month” blog posts — at least, all of them I could discover via public indices. If you discover any more, please tell me and I’ll add them here!

Read More

Dante’s hypersphere in THREE.js

Mark A. Peterson’s essay “Dante and the 3-sphere” (Am. J. Phys. 47(12), December 1979) suggests that when, in Paradiso 27, Dante looks from the starry sphere upward in the direction of the Empyrean and downward in the direction of Earth, and when he sees that nine concentric circles of angels above mirror the nine concentric planetary spheres below, he is “groping for a language to express an idea conceived intuitively and nonverbally” — namely, the idea of “how a 3-sphere would look from its equator.”

Read More

The crossword from Bored to Death S2E5

In HBO’s Bored to Death episode S2E5 “Forty-Two Down,” protagonist Jonathan Ames (Jason Schwartzman) introduces himself to his target Vikram (Ajay Naidu) by asking his help with that day’s New York Times crossword. We get two brief shots of the crossword itself. The first, a closeup, is just enough to irk the crossworders in the audience, as we see a plethora of unkeyed letters. The second medium shot shows that the black squares in this asymmetric grid spell out the word “HIT.” (Or does the black blob in front of the “H” represent a fourth letter?)

The episode aired 2010-10-24, but the Times shown is mostly the issue of Wednesday 2007-11-14: the facing column contains Mike Hale’s review of the TV show Kenny vs. Spenny, and the “Answer to Previous Puzzle” at lower left is indeed Fred Piscop’s puzzle of 2007-11-13. The crossword, however, is completely doctored — I see no resemblance to the Jim Page puzzle that actually ran on that date. The clues (which do not match the grid) are hilariously zany!

Read More