Questions tagged [compile-time]

Refers to the information that can be inferred or known at the time source code is compiled, as opposed to information that can only be inferred when source code is run. Do not use this tag for questions about the time it takes for source code to be compiled.

In , compile time refers to either the operations performed by a (the "compile-time operations"), requirements that must be met by source code for it to be successfully compiled (the "compile-time requirements"), or properties of the program that can be reasoned about at compile time.

The operations performed at compile time usually include , various kinds of (e.g., type checks and instantiation of template) and .

Programming language definitions usually specify compile time requirements that must meet to be successfully compiled. For example, that the amount of storage required by types and variable can be deduced.

Properties of a program that can be reasoned about at compile time include range-checks (e.g., proving that an array index will not exceed the array bound), deadlock freedom in concurrent languages, or timings (e.g., proving that a sequence of code takes no more than an allocated amount of time).

Compile time occurs before (when the output of one or more compiled files are joined together) and runtime (when a program is executed).

In some programming languages it may be necessary for some compilation and linking to occur at runtime.

There is a trade-off between compile-time and link-time in that many compile time operations can be deferred to link-time without incurring extra run-time.

"Compile time" can also refer to the amount of time required for compilation.

Source: Wikipedia

925 questions
12
votes
3 answers

A standard way for getting variable name at compile time

Is there some way in C++11 or higher to achieve a similar behavior to: int some_int; std::string x=variable_name::value; //Theoretical code std::cout << x; Result should be: some_int If not, is there a compiler specific way to do it?…
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
12
votes
1 answer

Force a narrow implicit coercion at compile time

I'm trying to define a struct which uses a variable with a restricted range of numbers, and implicit coercion from ints. I'd like to be able to force build errors if any constants or other hardcoded values are used with this struct. Here is an…
user3657661
  • 306
  • 3
  • 13
12
votes
5 answers

Delphi {$IFDEF CONSOLE} Problem

I just tried program Project1; {$APPTYPE CONSOLE} uses SysUtils; begin {$IFDEF CONSOLE} beep; {$ENDIF} end. and expected to hear a beep during runtime, but not. The following test works, though: if IsConsole then beep; Why…
12
votes
3 answers

static_assert depend on class template

Consider the following code: template struct myclass { unsigned int f() {return N;} unsigned int g() {static_assert(N > 0, ""); return N-1;} }; Question: Do I have the guarantee that the following code will…
Vincent
  • 57,703
  • 61
  • 205
  • 388
12
votes
3 answers

Merging global arrays at link time / filling a global array from multiple compilation units

I want to define an array of things, like event handlers. The contents of this array is completely known at compile time, but is defined among multiple compilation units, distributed amongst multiple libraries that are fairly decoupled, at least…
Matthijs Kooijman
  • 2,498
  • 23
  • 30
12
votes
6 answers

Why isn't the ArrayIndexOutOfBoundsException a compile time error?

Can someone explain to me why ArrayIndexOutOfBoundsException is a run-time exception instead of a compile-time error? In obvious cases when the indexes are negative or greater than the array size, I don't see why it cannot be a compile-time…
Laz London
  • 302
  • 1
  • 3
  • 11
12
votes
4 answers

Static Guarantee on Key/Value Relationships in Data.Map

I want to make a special smart constructor for Data.Map with a certain constraint on the types of key/value pair relationships. This is the constraint I tried to express: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, DataKinds…
cdk
  • 6,698
  • 24
  • 51
11
votes
4 answers

Generate unique numbers at compile time

I want to generate unique numbers for each class in my header, primes in my case primes but let's say this should only be consecutive numbers i.e. 1,2,3,4,etc. Of course I can hardcode these: struct A { enum { ID = 1; }; }; struct B { enum { ID = 2;…
helami
  • 2,099
  • 2
  • 14
  • 17
11
votes
1 answer

How to use "Template Constructors" in D?

The template documentation for D includes a small section called "Template Constructors". That section doesn't have any example or extensive documentation. I'm attempting to use that feature (I'm aware that I could just use a "static constructor",…
11
votes
2 answers

SASS: Set variable at compile time

Is it possible to set a sass variable at compile time? I basically want to do this: $color: red !default; div#head { background-color: $color; } When I compile to css I want to set $color to "blue" (preferably from the command line). Has anyone…
Kenzic
  • 525
  • 5
  • 15
11
votes
3 answers

Will instantiating templates in precompiled headers reduce compile times?

Example: Say I include in my precompiled header file: #include As a few instances of the vector, such as std::vector, std::vector etc are used often in my project, will it reduce compile time if I instantiate them as well in the…
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
11
votes
4 answers

C++98/03 std::is_constructible implementation

The base components of my hobby library has to work with C++98 and C++11 compilers. To learn and to enjoy myself I created the C++98 implementations of several type support functionality (like enable_if, conditional, is_same, is_integral etc. ...)…
Broothy
  • 659
  • 5
  • 20
11
votes
1 answer

Is it possible to realize the benefits of dependent typing using macros in Lisp?

This is an honest question, not a a troll. I'm asking for your patience. When Cedric talks about dependent types, the benefit he states is checking List lengths at compile time: Having a list with one element would be a type error, so the second…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
11
votes
3 answers

How can I initialize an array in compile-time with some elements given manually?

I'm using an array of pointer to function. I wrote the code like this since some of elements can not be expressed with function template. extern void zero(); // isr 0 is defined somewhere else void one() { // isr 1 } template
Inbae Jeong
  • 4,053
  • 25
  • 38
11
votes
2 answers

C++ compile-time bignum library

Is there any compile-time library (template metaprogramming) for arbitrary-precision arithmetic in C++? I need this to help with fixed-point arithmetic and binary scaling in my program for AVR microcontrollers. For example, when two numbers each…