Live data from Hacker News

Abusing C macros to render the Mandelbrot Set at compile-time

gist.github.com

1–10 of 23 posts

Re: Abusing C macros to render the Mandelbrot Set at compile-time

#5
This is really neat. I changed the quality value to 6: clang took ~20 minutes to compile and it used around 32GB of RAM. The resulting executable is 13KB, and it generates a 4KB image as output.

Here's a link of the output image: https://imgur.com/cUdForu

Re: Abusing C macros to render the Mandelbrot Set at compile-time

#8

This is really neat. I changed the quality value to 6: clang took ~20 minutes to compile and it used around 32GB of RAM. The resulting executable is 13KB, and it generates a 4KB image as output. Here's a link of the output image: https://imgur.com/cUdForu

Case in point: that 4KB output file refers to the size of the uncompressed PNM file, and as such is an inaccurate hint as to the image dimensions.

It's 64x64.

Re: Abusing C macros to render the Mandelbrot Set at compile-time

#9

Can we please have constexpr in C 2x to put an end to this madness?

As someone who doesn't do much C++, could `constexpr` actually do this all on its own? My (limited) understanding of `constexpr` would lead me to think that using it alone you couldn't generate the contents of the array like this. IE. You could define a `constexpr` function to calculate a single entry in the array, but you'd still need to call that function for every entry. In this case, it looks to me like the bulk of the macros here are just to condense declaring the large array by using nested macros to repeat the computations and expand to a large number of array entries.

That said I absolutely don't disagree with you at all. It's really a bit silly C doesn't have it at this point. `gcc` will happily do all of this math for you at compile time even if you do as much of the math as you can in `static` functions. But to make it compile you have to declare `pixels` in `main` because you can't call the functions in the initializer for file-scoped variables - even though the compiler can already optimize them out.

Post reply on HN