Questions tagged [constant-expressions]
Use this tag for question about expressions whose value is known at compile time.
7
questions
31
votes
4
answers
3k
views
Are there any advantages of evaluating expressions differently in compile time and runtime?
From https://rtfeldman.com/0.1-plus-0.2, on different floating point number semantics:
Go takes a different approach. When you write 0.1 + 0.2 in Go, that expression gets evaluated to 0.3 at compile ...
3
votes
1
answer
384
views
Why is type-punning at compile-time a no-go?
More on the topic of type-punning being problematic:
C23 added constexpr and new rules as to how compile-time constants can be created and handled. We can now ...
6
votes
2
answers
332
views
How useful is the traditional const in addition to constexpr and rvalue references?
In C++, there are two newly created features related to const: constexpr and rvalue references. (IMHO rvalue reference is not ...
4
votes
6
answers
1k
views
How can memory addresses be compile-time constants?
In C the memory address of a statically allocated object or a function is considered compile-time constant. For example this is valid code:
...
6
votes
1
answer
221
views
LSP for a language with a lot of compile-time execution
I'm currently designing a language with a heavy focus on compile-time code execution. In particular, all types will be handled as regular compile-time values (similar to the Zig language). This ...
13
votes
2
answers
2k
views
Why is it so difficult to implement the first Futamura projection?
The Futamura projections are a series of three transformations that can be performed on interpreters, compilers, and compiler-compilers respectively. These transformations rely on a specializer which ...
22
votes
2
answers
5k
views
Why is it so hard to evaluate functions with constant arguments at compile-time?
I noticed C23 has constexpr but only for variables, not for functions. While C++ does, this would allow a function to be defined in such a way that if the function ...