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

How to make C++ compile time template cast constant?

Is this the only way to initialize default parameter initial_value as a compile time constant of type TNumber? If not, what is the preferred method of doing so? template class Widget { public: Widget(TNumber initial_value =…
Roman
  • 13
  • 3
1
vote
2 answers

constant expression function in c++98

I have following problem with c++98 constant expressions. Here is an example for an template struct.. which will receive the size at compile time.. Is it somehow possible to get this size as constant expression without c++11 constexpr? Take a look…
1
vote
1 answer

constant expression required in Java behaviour change for int and Integer

For a little code , willing to save some Boxing/Unboxing hassle introduced because I further have to use an int constant as an Integer (mandated by Generics method call), I went from this simplified example enum SOQ { TYPEA, TYPEB, …
1
vote
3 answers

Evaluate all macros in a C++ header file

I have a requirement to build an automated system to parse a C++ .h file with a lot of #define statements in it and do something with the value that each #define works out to. The .h file has a lot of other junk in it besides the #define…
Techrocket9
  • 2,026
  • 3
  • 22
  • 33
1
vote
4 answers

How to define the size of an array that is a static member of a non instanciable class?

I'm writing a class I don't want to instantiate. All its members are static. This class represents a peripheral of a microcontroller. Since there is only one instance of that peripheral in the microcontroller doesn't make sense to me create…
user4546925
1
vote
1 answer

Defining an NSArray Constant in a Protocol

I have a protocol class where I'm defining multiple String Constants and Array Constants containing these strings. I am porting over an android project. In my Constants.h, I am declaring the NSString & NSArray constants as…
mhorgan
  • 886
  • 2
  • 11
  • 32
1
vote
3 answers

Convert compile-time-constant int to compile-time-constant String in Java

I have an annotation that requires a compile-time-constant String and I wanted to initialize it with a compile-time-constant int from one of the libraries I'm using. So what I ended up doing was something like this: public class LibraryClass { …
Parisbre56
  • 157
  • 2
  • 8
1
vote
0 answers

Is there a way to define the value of a constexpr value when compiling?

When using macros, it's possible to define the value when compiling with -D =. Can something similar to be done with constexpr values? To motivate the problem, consider the following code which generates a 12x12 multiplication table at…
erip
  • 16,374
  • 11
  • 66
  • 121
1
vote
1 answer

Do String constants/literals in code slow down compiling considerably?

String compile time constants (internalized-strings) and literals can be compared with the ==, as they are assigned the same reference at compile-time if they are equal somehow. Does this mean that compiling code consisting of n String literals…
1
vote
1 answer

Compile-time hashing with constexpr and CryptoPP

I am trying to hash some strings at compile time (they do not need to be retrieved) using the Crypto++ library and a constexpr function. This is the code I have so far: constexpr const char* operator "" _SHA3_HASH(const char *input, unsigned int…
Mutantoe
  • 703
  • 8
  • 20
1
vote
2 answers

Macro for use in expression while enforcing its arguments to be compile time constants

I am looking for a way to #define a macro that enforces its arguments to be compile time constants, and at the same time can be used in an expression. The method should be working under C90 and be upward compatible - if possible also portable for…
Mark A.
  • 579
  • 4
  • 13
1
vote
2 answers

Will this comparison be compiled into a constant Boolean value in a generic class?

Will typeof(T) == typeof(string) where T is a generic type argument, be compiled into a constant Boolean value, since the condition is knowable at compile time?
Triynko
  • 18,766
  • 21
  • 107
  • 173
1
vote
0 answers

Checking for compiler constants in app.config

In my C# project, I have little bits of code here and there that look something like this: #if DEV DoStuff(); #else DoOtherStuff(); #endif These enable me to deploy two slightly-different versions of my application. I use log4net to log…
1
vote
1 answer

assigning a Text box value to a constant variable in VBA

I want to assign a Constant global variable value dynamically from a user form input.This value will be used to declare the Typedef functions and other variables initially before running the actual Macro my code looks like this Const Imax dim sys…
1
vote
3 answers

What is the best way in C++ to have a compile-time constant depend on a type's size?

I was thinking one of these: #if sizeof(size_t) == 8 const size_t foo = 12345; #elif sizeof(size_t) == 4 const size_t foo = 123; #else #error "Unsupported size_t size" #endif or template class Foo { static const size_t foo = 0; }; template…
Matt
  • 21,026
  • 18
  • 63
  • 115