Starting out in zig and working my way through ziglings. I just finished the comptime section and I'm curious of the limits. Could you make your entire program-- up to interaction with outside systems-- comptime? Of course, this would just make compilation take longer instead of running take longer, I'm just wondering if it's possible
#Limits of comptime
1 messages · Page 1 of 1 (latest)
Not sure how much of the entire program could be comptime but this project from @crystal lagoon is an SSG that is built on zig build and comptime. https://github.com/kristoff-it/zine
yes, anything except (might not be complete):
- syscalls (so no interactions with the outside world at all)
- inline assembly
- runtime only things like the address of global variables
- calling functions in linked libraries either static or dynamic
Jeez, that's absurdly powerful
Glad I'm finally taking the time to learn zig. I was continuing to code in C, waiting for a zig spec. I got tired of waiting after I kept seeing the nice features
Thanks for the quick responses!
Comptime shines best when it’s used to define complex new types for your runtime code.
A current limitation of comptime code is that the addresses of data can’t be known .. so doing overly clever pointer arithmetic doesn’t quite work out the way you would expect.
This may change later in, but it’s non trivial to fix it.
It’s a bit of an edge case, and you need to descend deep into comptime programming rabbit holes before it bites you 🙂