Skip to main content

Questions tagged [constant-expressions]

Use this tag for question about expressions whose value is known at compile time.

Filter by
Sorted by
Tagged with
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 ...
osa1's user avatar
  • 411
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 ...
CPlus's user avatar
  • 9,063
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 ...
user23013's user avatar
  • 2,740
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: ...
CPlus's user avatar
  • 9,063
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 ...
abel1502's user avatar
  • 2,537
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 ...
Corbin's user avatar
  • 851
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 ...
user1345541's user avatar