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 constants as floats

After converting a file with doubles to floats the compiler (MSCV2005) warns about conversions from double to float for in code constants like ... float r; r = (q1 + q2) * 0.5; ... Even q1, q2 are both floats 0.5 seems to be treated as double. How…
embert
  • 7,336
  • 10
  • 49
  • 78
1
vote
2 answers

How to setup Flash Builder compiler constants ONCE for multiple projects in the same Workspace?

Is there any way to link some Flex or AS3 compiler options so that multiple projects in the same workspace can share the same Compiler Constants values? Basically, I will need to frequently change the "LANG_ENG" and "LANG_FR" to true and false, for…
1
vote
1 answer

How to compile a function for multiple values of a parameter known in compile-time

I'm writing a C++ function that at the moment receives a parameter via template. The function is complicated, but to simplify the question, consider a function like this: template int foo(int b){ return a+b; } But in the final program,…
Farzad
  • 3,288
  • 2
  • 29
  • 53
1
vote
4 answers

Why does casting null to type for method selection work?

According to the answer to C#: Passing null to overloaded method - which method is called?, nulls seem to carry type information. In fact, I can also use class Program { static void Method(TypeA a) { Console.Write("Output of…
jzx
  • 139
  • 1
  • 13
1
vote
3 answers

Declaring symbolic constants in header without initializing?

It is common practice to define symbolic constants in a header file: #define T_FOO 1 #define T_BAR 2 Ugly. static const int T_FOO = 1; static const int T_BAR = 2; Better, since not preprocessor. enum { T_FOO = 1, T_BAR } T_Type; Better…
DevSolar
  • 67,862
  • 21
  • 134
  • 209
1
vote
2 answers

XCode: Initializer element is not a compile-time constant

I am writing a program in C using XCode. I don't use C much, usually I use C++. I've never used XCode before. Compile error is quite simple, the following lines of code are not being treated as compile time constants by the compiler. const double PI…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
1
vote
1 answer

Is there an 'Integral constant overflow' warning in clang?

Consider the following snippets: short x = 2000000000; short x = (short)2000000000; int x = 1000000000 * 1000000000; Can we get an warning(/error) for these in Clang? How? Starting with what version? Thanks, Ciprian.
MciprianM
  • 513
  • 1
  • 7
  • 18
1
vote
2 answers

Compile-time access to class template's member by index

Given a template whose non-type parameter determines the size of a non-const int array member, how can I access the array elements by an integral index at compile time? I want the access to be done via the class template’s getter method at. I…
1
vote
1 answer

Performing one-off calculations within a SQL query

I have this query (edited for simplicity): select to_timestamp(s.sampletimestamp/1000) from sample s where s.sampletimestamp >= extract(EPOCH FROM TIMESTAMP WITH TIME ZONE '2013-08-11 00:00:00+10')*1000 and s.sampletimestamp < extract(EPOCH FROM…
1
vote
0 answers

Unclear about use of undefined SDK enum constants at runtime

It might be best to start with an example: In OS X the following enum constants are defined in Foundation/NSString.h: NSCaseInsensitiveSearch = 1, NSLiteralSearch = 2, NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7, 3_2) =…
1
vote
4 answers

Compile time size of string literal in array of string literals

I'm looking to find the length of a C-string literal at compile time. Given the definitions: static const char * const header_left[] = { " | | Raw | Raw |", " | | Start | End |", "Interval#|…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
0
votes
3 answers

Using a `constexpr static` function defined in a class to initialize a member of the same class

I am a little new to C++ and learning the language. Right now I'm using C++17 and G++. I'm trying to initialize an array of structs at compile time. I want to explicitly specify the array indexes in which my initial data goes which makes the process…
Stefan
  • 919
  • 2
  • 13
  • 24
0
votes
0 answers

Stateful const functions/ creating an enum from info available at compile time

This is a problem I’ve run into in several languages when creating libraries. Say I’m writing an event system. I might want to have several event keys, and it would be most efficient to store them as integers. My first thought would be to create an…
Jam
  • 476
  • 3
  • 9
0
votes
1 answer

C++: efficient compile-time looping and Boost::hana::while_() runtime cost

Problem statement I have been experimenting with strategies to resolve loops at compile time with C++. The algorithmic problem I aim to solve is as follows: given integer 4-tuple I = (i1,i2,i3,i4) all between 0 and 3(d-1) such that i1+i2+i3+i4 =…
0
votes
0 answers

How to add attribute with if else C#

I have options to use both SQL Server and PostgresSQL databases. In some classes, I have the following attribute [DatabaseGenerated(DatabaseGeneratedOption.Computed)] used to decorate to class properties: public class MyClass { #if define…
user3097695
  • 1,152
  • 2
  • 16
  • 42