Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Anyone have a non-terminating C compile? (Other than X11. I compiled that from scratch back in ancient times and it took a whole day. At least it seemed like it wasn't going to terminate.)


C doesn't support metaprogramming, unless you count the preprocessor language. With the preprocessor, you could have a couple files mutually #include each other...


I tried it:

    error: #include nested too deeply


struct cthulhu { char b[1024 * 1024 * 1024]; const char* name; } F = { {0}, "cthulhu" };


Indeed, this crashed my gcc. How does it work? If I had enough memory would it terminate? looks like it.


Because the structure is initialized, the compiler has to lay it out in memory, and fill out the fields.

If it was left uninitialized, it would've simply reserve space for it, but won't allocate anything in memory (compiler memory), and then the linker is just going to increase the BSS section (uninitialized data) with it's size.

Later the program may or may not run. Some systems might allow many gigabytes of uninitialized data. Others simply won't.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: