# Write the shortest program that generates the most compiler warnings and errors

## The challenge:

Write a very short program that, when compiled, creates the most amount of compiler warnings and errors. It can be written in any programming language.

## Scoring:

The score is determined by this equation: errors_and_warnings_length/code_length. Highest score wins.

## Example:

The C# program class is 5 chars long and generates 3 warnings, which is a score of (1/5)*3 = 0.6.

## EDIT:

Because of some confusion, programs have to be at least 1 char long. Otherwise it would get a score of infinity.

• While I like the concept, I find the metric a little worrisome. What compiler? What settings (especially with regard to warnings)? I mean gcc -Wall -pedantic is very different from plain ol gcc is different from tcc is presumably different from some other c compiler. – dmckee May 12 '12 at 16:18
• Just get a compiler in Russian, or German, you get some LONG errors(no pun intended) – hexafraction May 13 '12 at 0:02
• I'd love to see answers in languages other than C/C++. – Ken Bloom May 13 '12 at 14:10
• I would've liked it if the challenge was to generate as many different errors as possible – Hannesh May 24 '12 at 14:48
• Ahem. Otherwise its score would be undefined. – wizzwizz4 Apr 28 '16 at 17:20

## GCC, score 2200 / 36 ≈ 4.5 × 1058

#include __FILE__
#include __FILE__


I have not actually finished compiling this code, but based on testing and simple mathematics, it should produce a total of 2200 #include nested too deeply errors.

Of course, the program is trivially extensible. Adding a third line brings the score up to 3200 / 54 ≈ 4.9 × 1093. Four lines give 4200 / 72 ≈ 3.6 × 10118, and so on.

• Very clever answer. +1 – Prince John Wesley May 12 '12 at 16:59
• Very clever I agree, but I'd count that as 1 error ("nested too deeply"), not a separate error for each line of the backtrace. – Kevin May 13 '12 at 2:20
• @Kevin: Just to be clear, it should produce that error 2²⁰⁰ times, once for each possible path by which the nesting limit can be reached. The fact that each error also includes 200 lines of backtrace just makes the output even more verbose. – Ilmari Karonen May 13 '12 at 11:29
• Hmm. I could swear when I tried it last night gcc bailed after 1 error, but it appears to be running printing more now. Objection withdrawn. Incidentally, is 200 from the c standard? – Kevin May 13 '12 at 13:42
• @Kevin Per gcc.gnu.org/onlinedocs/gcc-4.8.2/cpp/Implementation-limits.html : "We impose an arbitrary limit of 200 levels [of nested #include], to avoid runaway recursion. The standard requires at least 15 levels." – zwol Jan 7 '14 at 15:12

## C, 0 characters - Score=(1/0)*1=Infinity

generates 1 error:

/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../crt1.o: In function _start':
(.text+0x18): undefined reference to main'
collect2: error: ld returned 1 exit status

• 1/0 is undefined, not "infinity". – Frank May 12 '12 at 16:23
• @jnm2 not sure about that. 1/0 is undefined and, although right side approaches +infinity, that doesn't make 1/0 defined at all. – kaoD May 12 '12 at 17:52
• Not to mention, @jnm2, by your logic 1/0 also is demonstrably smaller than 1 divided by any smaller number than 0. Making it 1/-1 = -1 > 1/0 > 1 = 1/1 ? – Ward Muylaert May 12 '12 at 18:12
• Since the domain is positive, I think what I said makes sense. Theory is fun but I think we need some common sense here. The most compiler errors for the least amount of code, remember. The limit is obvious. – jnm2 May 12 '12 at 19:56
• 1.0/0.0 = +INF, at least according to IEEE 754 :) So you just have to do the calculation in floating point. – Keith Randall May 12 '12 at 21:07

## GCC, score 5586.6 (and more if needed)

179 chars, 1000003 warnings/errors (using -Wall)

#define E a,a,a,a,a,a,a,a,a,a
#define D E,E,E,E,E,E,E,E,E,E
#define C D,D,D,D,D,D,D,D,D,D
#define B C,C,C,C,C,C,C,C,C,C
#define A B,B,B,B,B,B,B,B,B,B
_(){A,A,A,A,A,A,A,A,A,A}


This can be extended arbitrarily, of course. For example, using 10 #defines instead of 5 and a length of 20 "calls" instead of 10 would lead to a score of about (20**10)/(179*4) = 14301675977.65 (and would take quite some time to run ;)

• Using #define X(A) A,A,A,A,A,A,A and X(X(X(X(X(X(A)))))) you can duplicate code much faster. – ugoren May 13 '12 at 6:56

## HQ9++, 1 (limit of (n+29)/n)

The following emits the warning Warning: this is not a quine for each Q in the code.

QQQQQ...Q
Warning: this is not a quine


Small is good, right? Hmm...

• FWIW, this is a joke. If that wasn't obvious. – boothby May 29 '12 at 16:11

## GCC twice, 86

22 chars, 1898 errors+warnings on my system.
I'm sure this approach can be much improved, by choosing longer files with shorter names.

#include</usr/bin/gcc>

• /usr/bin/gdb is significantly larger (5.5M vs 760K), but /vmlinuz at 5.6M might be your best bet. – wchargin Mar 5 '15 at 3:59

## C, .727

11 chars, 5 errors, 3 warnings, (1/11)*8 = .727273

m(;){@,x}2


cc -g -Wall    er.c   -o er
er.c:1: error: expected declaration specifiers or '...' before ';' token
er.c:1: warning: return type defaults to 'int'
er.c: In function 'm':
er.c:1: error: stray '@' in program
er.c:1: error: expected expression before ',' token
er.c:1: error: 'x' undeclared (first use in this function)
er.c:1: error: (Each undeclared identifier is reported only once
er.c:1: error: for each function it appears in.)
er.c:1: warning: left-hand operand of comma expression has no effect
er.c:1: warning: control reaches end of non-void function
er.c: At top level:
er.c:1: error: expected identifier or '(' before numeric constant


• I count 5 errors, plus 3 warnings – Kevin May 13 '12 at 2:15
• I suppose you're right. I was counting the "error:" and "warning:" strings. – luser droog May 13 '12 at 2:30
• I think you win if we only count different errors/warnings. – ugoren May 13 '12 at 7:03
• If -Werror is used on the command line, warnings are promoted to errors. And also, which C compiler used will affect the number of reported errors (or if -Werror is available, etc.) One might argue the command line length for invocation might be counted as part of the "program" length... and each compiler version on each platform is a separate category. :-) – Dr. Rebmu Apr 3 '18 at 0:21

## NASM, score 63/40 * 2^32 ≈ 2.905 * 10^19

%rep 1<<32
%rep 1<<32
!
%endrep
%endrep


Will output c.asm:3: error: label or instruction expected at start of line 2^64 times. Again this is easily extensible to much bigger outputs.

C++98 (211 bytes) g++-5 (Ubuntu 5.2.1-23ubuntu1~12.04) 5.2.1 0151031

I wanted to see how well I could do in C++ without using the preprocessor at all. This program produces 2,139,390,572 bytes of output, most of which is a single error message.

template<int i,class S,class T>struct R{typedef R<i,typename R<i-1,S,S>::D,typename R<i-1,S,S>::D>D;};template<class S,class T>struct R<0,S,T>{typedef S D;};void f(){R<27,float,R<24,int*const*,int>::D>::D&E=4;}

me@Basement:~/src/junk$ls -l a.C -rw-rw-r-- 1 me me 211 Apr 27 21:44 a.C me@Basement:~/src/junk$ g++-5 a.C -fmax-errors=1 2>a.C.errors.txt
me@Basement:~/src/junk\$ ls -l a.C.errors.txt
-rw-rw-r-- 1 me me 2139390572 Apr 27 22:01 a.C.errors.txt


Ungolfed:

template <int i, class S, class T>
struct R {
typedef R<i, typename R<i-1,S,S>::D, typename R<i-1,S,S>::D> D;
};
template <class S, class T>
struct R<0, S, T> {
typedef S D;
};
void f() {
R<27, float, R<24, int*const*, int>::D>::D &E = 4;
}


This program works by defining a recursive struct template R which holds a typedef D containing two copies of R. This results in an type name which grows exponentially, which is printed out in full in the error message. Unfortunately, g++ seems to choke while attempting to print an error message longer than (1<<31) bytes. 2,139,390,572 bytes was the closest I could get to the limit without going over. I'm curious if anyone can adjust the recursion limits and parameter types 27, float, 24, int*const* to get closer to the limit (or find a compiler which can print an even longer error message).

Excerpts from the error message:

a.C: In function ‘void f()’:
a.C:1:208:  error:  invalid  initialization  of non-const reference of type
‘R<27, float, R<24, R<23, R<22, R<21, R<20, R<19, R<18, R<17, R<16, R<15,
R<14,  R<13, R<12, R<11, R<10, R<9, R<8, R<7, R<6, R<5, R<4, R<3, R<2, R<1,
int* const*, int* const*>, R<1, int* const*, int* const*> >, R<2, R<1, int*
const*,  int*  const*>,  R<1, int* const*, int* const*> > >, R<3, R<2, R<1,
int* const*, int* const*>, R<1, int* const*, int* const*> >, R<2, R<1, int*
const*,  int* const*>, R<1, int* const*, int* const*> > > >, R<4, R<3, R<2,
R<1, int* const*, int* const*>, R<1,
...
int*  const*,  int*  const*>  > > > > > > > > > > > > > > > > > > > > > > >
>::D& {aka R<27, R<26, R<25, R<24, R<23,  R<22,  R<21,  R<20,  R<19,  R<18,
R<17,  R<16,  R<15,  R<14, R<13, R<12, R<11, R<10, R<9, R<8, R<7, R<6, R<5,
R<4, R<3, R<2, R<1, float, float>, R<1, float, float> >, R<2,  R<1,  float,
float>,  R<1,  float, float> > >, R<3, R<2, R<1, float, float>, R<1, float,
float> >, R<2, R<1, float, float>, R<1, float, float> > > >, R<4,
...
, R<1, float, float>, R<1, float, float> > >, R<3, R<2, R<1, float, float>,
R<1, float, float> >, R<2, R<1, float, float>, R<1, float, float> > > > > >
>  >  >  >  >  >  > > > > > > > > > > > > > > >&}’ from an rvalue of type
‘int’
template<int    i,class   S,class   T>struct   R{typedef   R<i,typename
R<i-1,S,S>::D,typename  R<i-1,S,S>::D>D;};template<class  S,class  T>struct
R<0,S,T>{typedef                         S                         D;};void
f(){R<27,float,R<24,int*const*,int>::D>::D&E=4;}

^
compilation terminated due to -fmax-errors=1.


2,139,390,572 bytes / 211 bytes = 10,139,291.8

• This is why I always use STLfilt... Welcome to PPCG! This is a great first submission! – Mego Apr 28 '16 at 6:10
• Unfortunately it seems I misunderstood the challenge; it seems submissions are scored by the number of error messages, not the byte count. Obviously my 1 error entry is not very competitive. Perhaps my answer should be moved here – Calculating Nut Apr 28 '16 at 8:00

# SmileBASIC, 1/1 = 1

A


Generates the error Syntax Error in 0:1`

• SB only ever generates one error at a time, so this is really the only answer you can make. – snail_ Feb 3 '17 at 4:33