Bug Hunting Adventures #13: Prime Sums

“Why, yes; and not exactly that either. The fact is, we have all been a good deal puzzled because the affair is so simple, and yet baffles us altogether.”
― Edgar Allan Poe, The Purloined Letter

Below, you find a little C project that doesn’t do what it’s supposed to do, namely print the sum of the first 10 prime numbers. The program builds cleanly with gcc and clang; that is, without any warnings even when using -Wextra -Wall -pedantic -ansi as compiler options. It’s well-formed and doesn’t crash.

What’s the root cause of this bug? What’s the output of the program? Here are the files, you can also find them on GitHub:






3 thoughts on “Bug Hunting Adventures #13: Prime Sums

  1. Shlomo

    Yeah cause the array is filled in another file.
    The prime_table.h does not fill in the array.
    You’re defining the same variable 2 times.
    You can’t do this in c++.

  2. Mark

    It’s always the last place you’d expect, isn’t it? It seems like a good build system would at least warn you about that particular error.


Leave a Reply

Your email address will not be published. Required fields are marked *