16 bytes of Python that compile to 32 terabytes of bytecode (2016)
codegolf.stackexchange.com
codegolf.stackexchange.com
> How does this compile in another language such as C?
It doesn't; the C language doesn't implement arbitrary size integers, and therefore most C compilers won't fold constants of such large size.
If you used a library that provided BigInts (arbitrary size integers), and and the library also provided a compiler extension to fold BigInt expressions at compile time, then you would likely get a large executable as well (most of the size would come from the data section).
Oops, that was me. Sorry! I realized that it doesn't, and didn't want to leave what seemed possibly like a snarky question in the discussion, but I'm glad you picked it up and clarified the answer.
struct x struct z<x(x(x(x(x(x(x(x(x(x(x(x(x(x(x(x(x(y,x(y><y*,x(y*w>v<y*,w,x{}
A tiny 79 bytes that explodes into a huge stacktrace that takes an inordinate amount of time to finish processing.Also see https://codegolf.stackexchange.com/questions/1956/generate-t...
$ g++ test.cpp 2>&1 > /dev/null | wc -l
10223622
Ten million lines.The template expansion machinery is pretty much a purely functional language and the compiler is the interpreter. The stacktrace in this case is not of the interpreter itself but of the program being executed.
In fact understanding that template error messages are none other than execution stack traces is key to making sense them.
Initialize at least one member so that it gets placed in data section instead of bss resulting in binary size more or less the same as array. Although at least on my system various parts of toolchain start to break down once you reach 2GB limit.
const main[255<<21]={195};
You can also get around the 2Gb limit by using the -mcmodel flag, such as 'gcc -mcmodel=medium FILE'. But then actually compiling the thing takes a long time and a heck of a lot of memory: const main[-1u]={195};The C++ template answers are particularly scary...
At some point (to lazy to look up the flag) gcc added a template recursion parameter that stops trying to unroll everything at some sane depth. Now the code compiles quickly the .exes are reasonably sized/etc.
At the very least, I can't reproduce it.
% cat tmp.py
(1<<19**8,)*4**7
% python -m compileall tmp.py
% ls -l __pycache__/tmp.cpython-39.pyc
-rw-r--r-- 1 eesmith admin 167 Feb 16 12:21 __pycache__/tmp.cpython-39.pyc
Python 3.6 generates a 144 byte file. One of the comments says it caused a problem in Python 3.3.5.Another peephole optimizer gotcha that caused problems with older Pythons is at https://bugs.python.org/issue30416 :
def tuple20():
return ((((((((1,)*20,)*20,)*20,)*20,)*20,)*20,)*20,)*20
If you have Python 2.7 hanging about, try simply defining that function - you can't even ^C it!It doesn't explode in size.
The peephole optimizer is checking for uniqueness, via a dict, and evaluating hash() of that constant takes a very long time.
>>> 1<<2**8
115792089237316195423570985008687907853269984665640564039457584007913129639936
>>> 1<<3**8
114235622173779374328348175648643910549218134760744031862028761
...quite a few lines later...
52363416415356114173952
Ask students to explain wtf is going on...