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

compile-time constant StringFormat

I have a method for converting text to bitmap: private Bitmap ConvertTextToImage(string text, FontFamily fontFamily, float fontSize, FontStyle fontStyle, StringFormat stringFormat, float MaxWidth, float MaxHeight, Color backgroundColor, Color…
AmirSina Mashayekh
  • 498
  • 1
  • 5
  • 21
1
vote
1 answer

Compile-time Size of Struct Minus Padding

I'm trying to use Boost MPL and Fusion to calculate the size of a struct exclusive of any padding. This is my current best attempt: Live example template constexpr std::size_t sizeof_members(void) { using namespace std; namespace…
1
vote
3 answers

Custom strtoi function compile time issue

I am trying to implement a very simple strtoi function. It works fine when when the passed arguments are dynamically created (case 2 below). However, if the char is created by char[] which is allocated during compile time, I get a constant value on…
Scheir
  • 79
  • 5
1
vote
2 answers

Is there a way to avoid preprocessor macros when taking an argument from the compiler?

I am writing a library that needs to do some compile time calculations, and builds an array of compile time constants. The issue is I need a way to specify the max size of this array... The only way I know of is to make it a configurable option…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
1
vote
1 answer

How to define a constraint on class type if It has custom attribute?

there is any way to force a class to implement an interface , if It has an specific custom attribute? I want to have a compile time error , if the class with specific attribute does not implement an specific interface. [myAttrib] public…
hm1984ir
  • 554
  • 3
  • 7
1
vote
0 answers

What is cLongFixedRectangle?

Everywhere that I found online is just a raw definition like this: cLongFixedRectangle = 'lfrc', /* 0x6c667263 */ But nowhere do I see it documented or used. All I could figure out is that it seems to be defined mostly in Apple OSs…
Ky -
  • 30,724
  • 51
  • 192
  • 308
1
vote
1 answer

Is it possible to inline string without const enum?

I want to expoort string contsnt but in such way that it would be inlined in all places it is used it and variable von't be created. I know it's possible with const enum: const enum SomeEnum { SOME_VALUE =…
Qwertiy
  • 19,681
  • 15
  • 61
  • 128
1
vote
1 answer

Expression did not evaluate to a constant two level constexpr functions (compiler bug?)

I have the following code: #include template class A { public: inline constexpr static int size() { return I; } }; template inline constexpr auto size(const T& arg) noexcept -> decltype(arg.size()) { return…
lightxbulb
  • 1,251
  • 12
  • 29
1
vote
1 answer

constant-time implementation of variable rotation RC6 cipher

RC6 wiki uses variable left rotation value that depends on logarithmic value. Iam interested in finding a way to implement constant time c code of RC6. Is there open-source or an idea of how to implement the variable left rotation in constant-time…
hardyrama
  • 125
  • 6
1
vote
2 answers

Error in string array initializer: initializer element is not constant

I need to define some strings and an array initialized with those strings available to use by different pieces of the software. I thought in defining them in a header file like this: //.h file const char *serviceStateKindNormal = "Normal"; const…
y.luis.rojo
  • 1,794
  • 4
  • 22
  • 41
1
vote
2 answers

Compile Time Constant

I understood what a compile time constant rule is from Compile-time constants and variables. declared as final have a primitive or String type initialized at the same time as the declaration initialized with constant expression final int x =…
1
vote
2 answers

constexpr does not work/apply inside function call

I have implemented a constexpr compile-time hash-function, which works fine (i.e. is evaluated at compile-time) if called as constexpr auto hash = CompileTimeHash( "aha" ); but I need to use it in actual code as an argument to a function as in foo(…
1
vote
0 answers

Set variables at and depending on compile-time

Is there any way to set a constant to a value which depends on the time of compilation? I want my application to have a public static final String RELEASE_DATE = ""; similar to #define RELEASE_DATE __DATE__ in C, which contains the date when…
andrbrue
  • 721
  • 6
  • 15
1
vote
1 answer

Way to declare float compile-time constant in C

I know that I can declare a named compile-time constant in C for integers by using enums, but is there a way to declare named compile-time constants in C for floats as well, without using macros (I know that C++ has constexpr, but I am strictly…
Cpp plus 1
  • 990
  • 8
  • 25
1
vote
2 answers

Equivalent of C programming syntax "#define" in Julia language

In the C Programming Language, the #define directive allows the definition of macros within the source code. These macro definitions allow constant values to be declared for use throughout the code. Macro definitions are not variables and cannot be…