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

43

12

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.

user4234

Posted 2012-05-12T14:05:28.097

Reputation:

17While 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 olgccis different fromtcc` is presumably different from some other c compiler. – dmckee --- ex-moderator kitten – 2012-05-12T16:18:19.303

2Just get a compiler in Russian, or German, you get some LONG errors(no pun intended) – Reinstate Monica - ζ-- – 2012-05-13T00:02:30.883

2I'd love to see answers in languages other than C/C++. – Ken Bloom – 2012-05-13T14:10:24.440

4I would've liked it if the challenge was to generate as many different errors as possible – Hannesh – 2012-05-24T14:48:08.417

3Ahem. Otherwise its score would be undefined. – wizzwizz4 – 2016-04-28T17:20:40.847

1

On a related note, here's a link to the grand C++ error explosion competition http://tgceec.tumblr.com/post/74534916370/results-of-the-grand-c-error-explosion

– matts1 – 2016-09-12T10:53:25.883

Answers

95

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.

Ilmari Karonen

Posted 2012-05-12T14:05:28.097

Reputation: 19 513

6Very clever answer. +1 – Prince John Wesley – 2012-05-12T16:59:52.923

5Very 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 – 2012-05-13T02:20:00.637

Wow, very clever. Looks like we got a very clear winner! – None – 2012-05-13T08:35:02.473

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 – 2012-05-13T11:29:04.750

1Hmm. 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 – 2012-05-13T13:42:26.677

@Kevin: I've no idea, but that's what the limit seems to be for GCC. – Ilmari Karonen – 2012-05-13T13:44:40.340

1

@Kevin Per http://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 – 2014-01-07T15:12:05.563

1... and it's a good thing I don't hack on GCC anymore or I would feel I had to find some way to detect this scenario and bail out earlier. ;-) – zwol – 2014-01-07T15:14:13.917

48

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

Note: http://ideone.com/xdoJyA

l0n3sh4rk

Posted 2012-05-12T14:05:28.097

Reputation: 1 387

491/0 is undefined, not "infinity". – Frank – 2012-05-12T16:23:20.770

2@Frank, that depends on the number system. – user606723 – 2012-05-12T16:30:47.697

Fitting answer to this question. – nikhil – 2012-05-12T16:45:33.503

3+1 Even if 1/0 is undefined, it's demonstrably larger than one divided by any larger number. 0 takes the cake. – jnm2 – 2012-05-12T17:41:14.917

6@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 – 2012-05-12T17:52:19.623

1Limit doesn't say a whole lot about the value in the point. That only holds true if the function is continuous in that point. Take for example the sign function. – Ward Muylaert – 2012-05-12T18:10:24.927

3Not 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 – 2012-05-12T18:12:25.080

3Note that you can turn the link error into a compiler error. Using gcc's -pedantic switch wil give you: empty.c:1: warning: ISO C forbids an empty translation unit. – breadbox – 2012-05-12T18:46:27.600

5Since 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 – 2012-05-12T19:56:23.753

151.0/0.0 = +INF, at least according to IEEE 754 :) So you just have to do the calculation in floating point. – Keith Randall – 2012-05-12T21:07:40.857

3A zero-sized C code was accepted as the winner in the IOCCC, as the shortest self-replicating program, so it's a good precedence to accept it here. (the rules were, as usually, changed after that submission, but it still counts) – vsz – 2012-05-12T21:13:37.160

2In Maths, 1/0 is infinity and it is 0/0 which is undefined. – manojlds – 2012-05-13T06:42:03.657

I've modified the rules. Sorry, but your program is disqualified. +1 for the idea, though. – None – 2012-05-13T08:36:38.183

2@manojlds Incorrect. The limit is, in some cases, +infinity. However imagine the limit of 1/(-(x^2)) when approaching zero, suddenly it's 1/0 = -infinity. And what about 1/sgn(x)? Now the limit coming from the positive side is +1 and the limit from the negative side is -1. – Ward Muylaert – 2012-05-13T13:24:54.693

2@WardMuylaert what you say is right, sgn(x) matters, but in this case x is the number of characters of code, which cannot be negative, so the limit must come from +1 side. Also, when I wrote infinity there all that was on my head was 1/10 < 1/1 < 1/0.1 < 1/0.01 < 1/0.001 <.....<1/0. :P – l0n3sh4rk – 2012-05-13T14:33:36.463

2

1/0=∞ in arithmatic on the real projective line. So like it was said before, this is just a matter of the number system you are using.

– scleaver – 2012-10-01T15:15:16.393

19

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

schnaader

Posted 2012-05-12T14:05:28.097

Reputation: 1 132

7Using #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 – 2012-05-13T06:56:16.720

12

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>

ugoren

Posted 2012-05-12T14:05:28.097

Reputation: 16 527

3/usr/bin/gdb is significantly larger (5.5M vs 760K), but /vmlinuz at 5.6M might be your best bet. – wchargin – 2015-03-05T03:59:35.457

12

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

boothby

Posted 2012-05-12T14:05:28.097

Reputation: 9 038

FWIW, this is a joke. If that wasn't obvious. – boothby – 2012-05-29T16:11:09.180

10

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

luser droog

Posted 2012-05-12T14:05:28.097

Reputation: 4 535

I count 5 errors, plus 3 warnings – Kevin – 2012-05-13T02:15:48.877

I suppose you're right. I was counting the "error:" and "warning:" strings. – luser droog – 2012-05-13T02:30:03.247

5I think you win if we only count different errors/warnings. – ugoren – 2012-05-13T07:03:12.373

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. :-) – HostileFork says dont trust SE – 2018-04-03T00:21:30.677

8

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.

copy

Posted 2012-05-12T14:05:28.097

Reputation: 6 466

2

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

Calculating Nut

Posted 2012-05-12T14:05:28.097

Reputation: 51

This is why I always use STLfilt... Welcome to PPCG! This is a great first submission!

– Mego – 2016-04-28T06:10:57.637

1

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 – 2016-04-28T08:00:43.517

-1

SmileBASIC, 1/1 = 1

A

Generates the error Syntax Error in 0:1

12Me21

Posted 2012-05-12T14:05:28.097

Reputation: 6 110

SB only ever generates one error at a time, so this is really the only answer you can make. – snail_ – 2017-02-03T04:33:16.050