Hidden reinterpret_casts

Here’s a fun little puzzle, courtesy of Richard Hodges on Slack.

template<class Vector>
void test(Vector& vec) {
    using E = decltype(vec[0]);
    for (int i=0; i < 10; ++i) {
        vec.push_back(E(i));
    }
}

int main() {
    std::vector<double> v;
    test(v);
    for (int i=0; i < 10; ++i) {
        printf("%f\n", v[i]);
    }
}

On any compiler you care to name, this code compiles with no warnings or errors — and produces utter garbage at runtime! Can you spot the bug? Spoiler below the break. …

Read More

The Story of Mel

“The Story of Mel,” Ed Nather, May 1983. I’ve always liked this story since the first time I encountered it as an appendix to the Jargon File. In 1992 Ed Nather commented: “The original submission [to net.followup] was not in free verse, nor any approximation to it — it was straight prose style, in non-justified paragraphs. In bouncing around the net it apparently got modified into the ’free verse‘ form now popular. In other words, it got hacked on the net. That seems appropriate, somehow.” (The free-verse version was already circulating sometime before November 1984.)

Read More

De Canibus Britannicis

This week I’ve been reading John Caius’s De Canibus Britannicis (1570), or rather, Abraham Fleming’s 1576 translation titled Of Englishe Dogges. The most immediately notable thing about the Project Gutenberg text is that it faithfully reproduces all the spelling quirks of the original’s Elizabethan English, including the indistinction of u and v (“reuenge”, “vpon”) and even the occasional use of scribal abbreviations to save space in the column (“thẽ” for “them”; “ye” for “the”). Besides these paleographic quirks, it also contains some fun facts about dogs.

Read More