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
2 answers

"error: initializer element is not constant" when using bitshift but not add or subtract, in C

My embedded system has two regions of memory. I created macros to switch between these regions. I would like to be able to execute these macros at compile time but I'm getting error: initializer element is not constant for certain operations and…
benathon
  • 7,455
  • 2
  • 41
  • 70
0
votes
1 answer

What does mean by "symlinks resolved" in the description of magic constant __FILE__?

I'm using PHP 7.2.0 Below is a description of magic constant __FILE__ : The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned. I didn't understand meaning of the…
user9059272
0
votes
2 answers

Defining a large constant string in a header?

If I define a large constant string in a header file that is included multiple times, will it create multiple copies of the constant string in the executable? (If it does, is there a way to avoid this without needing a separate source file?) This…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
0
votes
1 answer

Use of undefined constant DIR_CACHE - assumed 'DIR_CACHE'

I was trying to upgrade my opencart version 1.5.6.4 to the latest one, 3.0.2.0 and followed all the instructions and was able to do it. I did the install procedure from mysite.com/install but got the error 1051 which i fixed by a solution…
Vaibhav Dwivedi
  • 55
  • 1
  • 3
  • 13
0
votes
1 answer

Java naming convention for 'private final' class fields & their use

I was reviewing some code written by a colleague who is my senior. In a unit test class, he made use of private final class variables like this: public class SomeProcessingServiceUT { private final String modelNumber = "ABC01"; private final…
user2918640
  • 473
  • 1
  • 7
  • 25
0
votes
0 answers

Define Dlib C++ constant matrix

I found one post about this but it wasn't really relevant. Hence my question: how does one define a Dlib matrix as a global compile-time constant? See attached example. Thank you.. #include #include "dlib/matrix.h" using namespace…
Marzz
  • 49
  • 6
0
votes
0 answers

Why using Integer reference as case constant in switch giving error?

public class Switch { public static void main(String[] args) { final Integer i=new Integer(2); switch(i) { case i:System.out.println("hi"); } } } When I am compiling it then it is giving error…
0
votes
1 answer

Is there a way to define a switch-compliant constant for static object members?

I understand that I can't use the result of getValue() in a switch statement because the case tree is built at compile time. What I have is a class which contains static const members that have a constant value set at runtime from a constructor. The…
Zhro
  • 2,546
  • 2
  • 29
  • 39
0
votes
2 answers

Compile-time boolean operations for an integral_constant?

In the C++ standard library, are there template types that are boolean operations on integral_constant (where X is either true or false)? As a simple example, you have two overloads of a function as such: void foo_impl(false_type){ cout…
Bernard
  • 5,209
  • 1
  • 34
  • 64
0
votes
2 answers

Is there a constant expression that is not a core constant expression?

According to cppref, a constant expression is not bound to be a core constant expression. My question: Is there a constant expression that is not a core constant expression?
xmllmx
  • 39,765
  • 26
  • 162
  • 323
0
votes
3 answers

Is this a BUG of VC++ 2010? About declaring a constant object in a header

Several lines of code are worth a thousand words: I have three simple files: header.h, main.cpp, other.cpp ==== CODE BEGIN ==== // header.h #pragma once const void* p = 0; // main.cpp #include "header.h" int main() { return 0; } //…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
0
votes
4 answers

Static data structures

Is there any way to create Map or Set type data structures at compile time? The reason I ask this is because I'm working with App Engine and I have some data structures that need to be sorted and searched, but they're constant, so I'd like to avoid…
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
0
votes
0 answers

Can we have leading zeroes in hexadecimal constants?

I am using C and Assembler on different platforms as well as VB.net for .NET development on Windows. In VB.net, when having long lists of constants or enums, I find it particularly annoying that the IDE does not seem to allow leading zeroes in…
Binarus
  • 4,005
  • 3
  • 25
  • 41
0
votes
2 answers

Choosing O(n) over O(1) when for all of n, O(1) is faster than O(n)?

Example of when I would choose O(n) algorithm over O(1) algorithm if for all of n, O(1) is faster than O(n)
D.Life
  • 11
  • 1
  • 2
0
votes
1 answer

Avoiding Replacing Constant Reference With a Literal When Compiled

I've discovered that when a constant (static final, initialized at compile time) is declared in one project, references to it in another project are replaced by a literal when compiled. It seems the only way to avoid this and have references refer…
Elly
  • 63
  • 8