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

C# Idiomatic runtime expression which always evaluates to true but is not detected as compile-time constant

I would like to have a C# runtime expression which always evaluates to true, but which the compiler does not recognize as a constant. (Motivation below) There are plenty of ways to achieve this, but I'm wondering if there's a nice most-idiomatic…
0
votes
0 answers

Algorithm to generate all array representations of numbers in base 6 of 3 figures, with specific order?

I am trying to figure out a way to generate a sequence of arrays of integers at compile time (using constexpr functions). The sequence is this one: // first all order 0 numbers {0, 0, 0}, // then all order 1 numbers (total sum of figures = 1) {1, 0,…
0
votes
1 answer

Branching out templated code based on a non const bool

This is the function I'm trying to simplify: void BaseCharacter::ClimbLadder(float AxisValue) { if (AxisValue > 0.f) ClimbUpLadder(); else if (AxisValue < 0.f) …
0
votes
3 answers

Where is the description of Constant Folding in the Java Language Specification, Java SE 11 Edition (JLS SE 11)?

As far as I know, Java deals with constant variables §4.12.4 by constant folding in compile time. I've tried my best, but I couldn't find its description from JLS. Could anybody tell me where I could find official description of the constant folding…
Frank Mi
  • 452
  • 3
  • 11
0
votes
2 answers

Generating floating point limits at compile time via template arguments and constexpr semantics:

I'm working on a set of classes. My Function class will take a Functor class which stores a function pointer to some defined function which has an operator that will invoke the function call from the function pointer. It uses a Limit class that…
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

Where to define compile-time constants?

I made a super simple design to start solving a problem. Now, this might seem like super trivial at first, but since there are tons of ways to do this, it confuses me, due to my lack of professional experience. Where would I define those compile…
Vinícius
  • 15,498
  • 3
  • 29
  • 53
0
votes
2 answers

Force a constexpr function to be compiled at compile time, even if calculation inside contains a non-const array, by making the returned obj constant?

I read about constexpr functions and when they do a compile time calculation. Now i am at a point, where i have to fill an array with new values, thus the array cannot be const. From what i know, a constexpr function is definitely evaluated at…
M.Mac
  • 699
  • 3
  • 14
0
votes
0 answers

Static map class to value "expression must have a constant value" in std::type_index

I am trying to build a structure in C++ that holds classes as keys and has ints as values. I would like to have this a sort of static map, which I can then use in my program to access the int associated to a certain class easily. This is the code…
Michele Piccolini
  • 2,634
  • 16
  • 29
0
votes
1 answer

How convert constant float value to 4 bytes hex constant value in compile time?

How convert constant float value to hex in compile time? In runtime i do in this way: int main() { union float_to_int { float float_; int int_; }; …
cYeR
  • 145
  • 1
  • 10
0
votes
0 answers

How to use a external value in @Pointcut

I am writing a common component for team members.So I write an aspect with Spring-aop.Ideally,what others only need to do is defining an point-cut expression in .properties or others.But I find it is a bit difficult。 I have searched some information…
wutingjia
  • 23
  • 7
0
votes
1 answer

Determine whether a String is a compile-time constant

Given a reference to any String, is it possible to programmatically determine whether this is a reference to a compile time constant? Or if it's not, then whether it's stored in the intern pool without doing s.intern() == s? isConst("foo") …
Bart van Heukelom
  • 43,244
  • 59
  • 186
  • 301
0
votes
2 answers

Correctly formulate conditions for constants?

I have a constant in my project, that represents some timespan. When it is below 0, I want to disable the timespan related checks. Normally one would check if(CONSTANT > 0) foo(); else bar(); but this causes the warning "Condition is always…
dCSeven
  • 815
  • 8
  • 18
0
votes
1 answer

How can PRODUCT_BUNDLE_IDENTIFIER be used as NSErrorDomain for app errors?

How can the product bundle identifier of an OS X app be used for an error domain? Are there any pitfalls of using it so? It doesn't seem to be defined as a macro; I tried: NSErrorDomain BSDomain = PRODUCT_BUNDLE_IDENTIFIER; This results in an…
outis
  • 75,655
  • 22
  • 151
  • 221
0
votes
0 answers

Do Java compilers calculate constant expressions during the compilation?

I've noticed that enum values in java.util.concurrent.TimeUnit have methods something like: public long toMillis(long d) { return x(d, C3/C2, MAX/(C3/C2)); } Are expressions C3/C2 and MAX/(C3/C2) calculated during compilation or during runtime?
0
votes
1 answer

C: map a command-line arg to a compile-time constant

I'm writing a C program that accepts a system resource name (e.g. RLIMIT_NOFILE) and prints some resource limit info for it. The resource constants are defined in , e.g. #define RLIMIT_NOFILE 5 I'm looking for a good way to map…
ivan
  • 6,032
  • 9
  • 42
  • 65