Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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: (1/length)*errors_and_warnings

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.

share|improve this question
10  
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
1  
Just get a compiler in Russian, or German, you get some LONG errors(no pun intended) – ObsessiveSSOℲ May 13 '12 at 0:02
1  
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

7 Answers

up vote 56 down vote accepted

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.

share|improve this answer
6  
Very clever answer. +1 – Prince John Wesley May 12 '12 at 16:59
3  
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
Wow, very clever. Looks like we got a very clear winner! – Printfn May 13 '12 at 8:35
1  
@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
1  
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
show 1 more comment

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
share|improve this answer
31  
1/0 is undefined, not "infinity". – Frank May 12 '12 at 16:23
5  
@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
3  
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
5  
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
7  
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
show 12 more comments

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 ;)

share|improve this answer
4  
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

GCC .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

share|improve this answer
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
3  
I think you win if we only count different errors/warnings. – ugoren May 13 '12 at 7:03

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>
share|improve this answer

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.

share|improve this answer

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...

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.