Questions tagged [compile-time-constant]

Use this tag for questions related to the compile time constant, a constant value that is known at compile time.

A expression is an expression denoting a value of primitive type or a String that is composed using only the following:

is uses in its general meaning, but you should provide the relevant tag of your programming environment, if any.

300 questions
0
votes
0 answers

workaround for not being able to use natural log in constant assignment

I am trying to write a program to find the nth prime. To do this I use the limit given by the prime number theorem: p(n) < n(ln(n) + ln(ln(n)) to calculate an upper bound for the nth prime number, use constant generics to create an array of that…
Pioneer_11
  • 670
  • 4
  • 19
0
votes
2 answers

include_str for null terminated string

I need to read a file into a null terminated string at compile time. Working in Rust OpenGL. I have a shader source code stored in a separate file. The function that will eventually read the source is gl::ShaderSource from the gl crate. All it…
DanielV
  • 643
  • 4
  • 14
0
votes
0 answers

How to demonstate that 2^F(x) is compile-time knowing that F(x) is a compile-time function

Sorry for my english. I don't know if I use the right terminology. DEF.: F is a compile-time function if exist the Turing machine which run-time doesn't depend on the input. I know that for the demostration I need to build a Turing-machine but I…
0
votes
1 answer

count #define or const variables at compile time

In C++, I have some #define and also a count like this: #define USE_1 #undef USE_2 #define USE_3 const size_t NUM_USE = ( 0 #ifdef USE_1 + 1 #endif #ifdef USE_2 + 1 #endif #ifdef USE_3 + 1 #endif ); Now, I…
Ernie Mur
  • 481
  • 3
  • 18
0
votes
0 answers

Is it possible to fill an array at compile time with a loop

I want to have a pre filled array (or vector) that should be part of the executable, that is being calculated at compile time. For example. I want a templated array or vector that can be filled with 0 to size with a counter value. I am targeting…
DEKKER
  • 877
  • 6
  • 19
0
votes
1 answer

Why Cant I Substitute a String into a NTTP

Take the following example: template class B {}; int main() { B<"abc"> b; return 0; } I have tried several variants of this, I dont understand why it does not work, it works for this library, it supports the…
0
votes
2 answers

What data types in C language are these variables and where I am wrong?

Now I am learning the C language and I have two tasks. Define variables and print them Here is my code: #include int main() { printf("Excersise 1\n\n"); int cVarOne = -250; int cVarTwo = 250; int cVarThree = 4589498; …
0
votes
1 answer

Apparent GCC bug with comma operator in constant initializer

I was messing around with C and discovered an apparent bug in GCC: #include int y = (1, 2); int main() { return 0; } in gcc gives error: initializer element is not constant while it works fine in clang. And as expected, putting the…
0
votes
0 answers

Natural logarithm cannot be computed in Delphi const at compile time

As I understand a thumb rule for allowing expressions in Delphi constants is that the expression should be able to get evaluated in complile time. So it's greatly unclear for me why the following is not allowed ([dcc64 Error] E2026 Constant…
0
votes
0 answers

Is deducing template integer parameter from compile-time-known function-parameter possible?

There is a struct and a generator function for it template struct Foo { int buffer[Size]; }; template Foo generate(int Size) { return Foo(); } and it produces this error: : error: declaration of 'int Size'…
huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97
0
votes
0 answers

Is there a way of getting the executable file's name in C without using argv[0]

This question is just out of curiosity. I thought there might be a predefined macro or something but couldn't find anything. If impossible, is it appropriate to use a constant global variable initiated with argv? I really don't know why the question…
0
votes
1 answer

Array constant not evaluating to constant even though only constexpr functions called in initialization

This is a simplified, reproducible version of my code: type_id.h template void type_id() {} typedef void(*type_id_t)(); c_sort.h (based on this answer) template constexpr void c_sort_impl(Array& array_) noexcept { …
JensB
  • 839
  • 4
  • 19
0
votes
0 answers

Why does constexpr not compute at compile-time for a string literal?

#include #include constexpr auto strlen_1(char const* sz) { auto const* p = sz; while (*p) { ++p; } return p - sz; } consteval auto strlen_2(char const* sz) { auto const* p = sz; while (*p) { …
xmllmx
  • 39,765
  • 26
  • 162
  • 323
0
votes
1 answer

Compile Time Union Array

I am trying to keep track of segments of varying size within a contiguous block of memory. The size and order of the segments are known at compile time so I would like to calculate their offsets within the block at compile time as well. I would like…
Ryoku
  • 397
  • 2
  • 16
0
votes
1 answer

Constant in separate namespace using class/struct with a big constuctor

I have a struct: struct ColorspaceData { private: glm::vec3 sMatrix; public: /// X red float xr; /// Y red float yr; /// Z red float zr; /// X green float xg; /// Y green float yg; /// Z green …
Wusiki Jeronii
  • 159
  • 1
  • 8