Live data from Hacker News

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

gist.github.com

11–20 of 23 posts

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

#11

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…

Everything above and including #define C1 returns a single value, and therefore could be done with constexpr.

More to the point, constexpr would be a heck of a lot more efficient - changing M4 to M5 increases the preprocesed size from 80 MB to 240 MB. This is an exponential increase, despite that a Mandlebrot pixel can be computed in linear time. (Linear to the maximum number of steps.)

I suspect that this is because if you write a macro and use your macro argument twice, this doubles the length of whatever your macro argument was.

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

#15

Just as a FYI, this takes a while to compile: $ pbpaste | time clang -x c - 99.35 real 82.72 user 9.94 sys If you're using iTerm, you can pipe the output of the program to imgcat to see the result without leaving your terminal.

gcc mandel.c -o mandel 95.84s user 3.99s system 71% cpu 2:18.88 total

thought it was just my notebook :) think it is the longest my machine spent on just 41 lines of code to compile

Post reply on HN