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
2
votes
1 answer

SystemVerilog: How come the enum next() method cannot be used in a constant function?

I have a package containing a number of packed-struct typedefs and I am trying to write a CONSTANT function to tell me the maximum bit width of these structs. Each struct has an explicit message_type which is enumerated. I believe the below function…
2
votes
1 answer

Expose private internal class size

I need to expose a compile time constant with the size of internal class. To do so I tried next code: #include struct A { //consider Private class as private for this example, just to be able to put the assert like this in main …
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
2
votes
1 answer

Fixed-Size Bit-Array in D

If I want a compile-time-sized bit-array (on stack) what are my alternatives? I'm thinking something like struct Bitset(size_t nBits) { enum wsz = 8 * size_t.sizeof; // Word-Size. enum nBlocks = nBits/wsz + nBits % wsz * wsz; alias _bits…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
2
votes
3 answers

C++ Declare array whose size value from const array

I'm trying to define a stack c-style array whose size is taken from const array and is known in compile-time. const int size[2]={100, 100}; int ar[size[0]]; //error: expression must have a constant value It fails. How it can be fixed?
Mark Kahn
  • 1,130
  • 10
  • 8
2
votes
2 answers

Maybe class and optional parameters

I have an implementation of a Maybe / Option class in c#. Basic implementation is public delegate Maybe Converter(TInput input); public delegate TOutput ElseDelegate(); public delegate Maybe
bradgonesurfing
  • 30,949
  • 17
  • 114
  • 217
2
votes
1 answer

Error 1046:Type was not found or was not a compile-time constant

I'm trying to make a interactive flash video in CS6 for a class I am taking. I briefly talked with the professor about this and he could not figure out the issue either. The weird thing is it says the errors are on lines 2 and 3. When I remove the…
2
votes
1 answer

Is there a way to embed a compile-time dynamic timestamp in a Flash AS3 movie?

Background: I manually update a version timestamp in my Flash document, which is displayed on the log-in screen of the application at run time. This helps me verify that I have the latest version loaded in the browser, rather than some cached…
Triynko
  • 18,766
  • 21
  • 107
  • 173
1
vote
6 answers

Java - static initialization

I have written a piece of code : public class Child{ int y ; private static final int z = getZ(); static { System.out.println("The value of z is "+z); } public int getX(){ System.out.println("get x"); return 10; } public int getY(){ …
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
1
vote
1 answer

Constexpr / Compile time constant expressions bugs

I get the following error in my project upon compiling. Tried everything but unable to resolve this. Reproduced the error here: https://replit.com/join/egfoiwpgig-darshanpandhi Error error: constexpr variable 'noOfTiles' must be initialized by a…
1
vote
0 answers

C++11 compile time calculation of constant array

I have class with variadic template parameters like this: template class TClass { public: static constexpr std::size_t S = sizeof...(Ns) + 2; static constexpr std::array N = {N1, N2,…
bko
  • 31
  • 4
1
vote
1 answer

In Rust can you associate a constant value to each enum variant and then collect those values at compile time?

Let's say I have an enum, and I want to somehow annotate or associate each variant with a &str. E.g.: enum MyEnum { A, // "foo" B(String), // "bar" C(i32) // "baz" } I would also like to collect these &str's into an array like const…
1
vote
1 answer

constexpr pow() function compiler fail

If I try something like: template constexpr decltype(X) const_pow() noexcept { return !E ? 1 : 1 == E ? X : (E % 2 ? X : 1) * const_pow(); } I get an error: prog.cc: In instantiation of 'constexpr decltype (X)…
user1095108
  • 14,119
  • 9
  • 58
  • 116
1
vote
1 answer

Can C-preprocessor can output as a string the evaluation of compiled known constants values(e.g. 150000UL/1000UL)? #define arithmetics

I'm wondering if it can be written that the prepocessor evaluates assigned constants known at compile time and returns the result as a string. I believe the answer is no or complex, but I'll give a try. Basically I have constants which are expressed…
1
vote
3 answers

Load file contents into a static array of bytes

I have a static array initialized with some constant value: static PROG_ROM: [u8; 850] = [0x12, 0x1d, ...]; I would like to instead load at compile-time the contents of a file into it. Sounds like a job for std::include_bytes!, however, I have two…
Cactus
  • 27,075
  • 9
  • 69
  • 149
1
vote
2 answers

CsvBindByPosition : value for annotation attribute must be a constant expression

I am trying to read a CSV file whose header position numbers comes from a property file. I get the position number for the fields using @Value. But however I am unable to bind this value as the position for @CsvBindByPosition. Here is my code…