Skip to main content
7 of 7
edited tags
MD XF
  • 13.9k
  • 4
  • 66
  • 104

1 character typo generating most error messages from C++ compilation

It seems that simple changes to a C++ file, especially with templates, can generate pages of errors. This contest is to see what the largest "bang of the buck" is, that is the more verbose error output with the smallest change to the source code (1 character addition).

Because other languages are more sane, this will be limited to C++ and gcc version 4.x.

Rules

  1. Original source file must compile with gcc 4.9.2 to object code without error.

  2. One ASCII character is added to source code to create a typo, increasing file size by 1 byte.

  3. Compiler is run with default options. Necessary options like -c and -std=c++11 are allowed, options like -Wall are not.

  4. Metric is

        number of bytes of generated error messages
        -----------------------------------------------------------------------
        (bytes of source code with typo) (length of filename passed to compiler)
    
  5. Answers will be validated with http://ideone.com/ C++ 4.9.2.

Example:

Filename is a.cpp, which is 5 bytes long.

int foo();

Working Compilation

 gcc -c a.cpp

Corrupted source code:

in t foo();

Failing Compilation

$ gcc -c a.cpp
a.cpp:1:1: error: ‘in’ does not name a type
in t foo();
  ^
$ gcc -c a.cpp |& -c wc
64
$ wc -c a.cpp
12 a.cpp

Score: 64/12/5 = 1.0666

Better attempt: Insert { between parens of foo()

$ gcc -c a.cpp |& wc -c
497

New score: 497/12/5 = 8.283

Good Luck!

UPDATE

I encourage people to ignore the recursive implementation. That technically wins but is not in the spirit of the contest.

UPDATE 2

As many people have noted, the contest probably would have been more interesting if the C pre-processor was not allowed. So I would like to encourage people to post solutions that do not use pre-processor commands at all. That implies no use of any header files at all, since #include is not allowed!

As far as using IDEONE to validate, you are allowed to either use the IDEONE output directly (and the source name as prog.cpp), or you can run the IDEONE output through a global search and replace (s/prog.cpp/a.cc/ for example) and pretend that you were able to set the file name directly.

UPDATE 3

As people pointed out, Ideone is a little too restrictive, requiring linkage not just object file creation. As this contest is purely in the name of fun, please be honest and specify what you used to get your score. Either use ideone, or use the most vanilla build (all defaults) of gcc 4.9.2 as you can muster. The contest is intended to bring awareness to the awfulness of C++ error messages.

Mark Lakata
  • 1.6k
  • 12
  • 13