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
482
votes
26 answers

Runtime vs. Compile time

What is the difference between run-time and compile-time?
devforall
  • 7,217
  • 12
  • 36
  • 42
126
votes
7 answers

Compile time vs Run time Dependency - Java

What is the difference between compile time and run time dependencies in Java? It is related to class path, but how do they differ?
Kunal
  • 2,929
  • 6
  • 21
  • 23
125
votes
10 answers

Can a program depend on a library during compilation but not runtime?

I understand the difference between runtime and compile-time and how to differentiate between the two, but I just don't see the need to make a distinction between compile-time and runtime dependencies. What I'm choking on is this: how can a program…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
125
votes
16 answers

Static assert in C

How can compile-time static asserts be implemented in C (not C++), with particular emphasis on GCC?
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
117
votes
31 answers

Cycle inside ; building could produce unreliable results: Xcode Error

I am trying to move to the new build system when compiling with Xcode 10. However, it gives the following error: Cycle details: → Target 'project' : LinkStoryboards Target 'project' has compile command with input…
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
113
votes
7 answers

Detecting CPU architecture compile-time

What is the most reliable way to find out CPU architecture when compiling C or C++ code? As far as I can tell, different compilers have their own set of non-standard preprocessor definitions (_M_X86 in MSVS, __i386__, __arm__ in GCC, etc). Is there…
Alex B
  • 82,554
  • 44
  • 203
  • 280
113
votes
14 answers

C++ Get name of type in template

I'm writing some template classes for parseing some text data files, and as such it is likly the great majority of parse errors will be due to errors in the data file, which are for the most part not written by programmers, and so need a nice…
Fire Lancer
  • 29,364
  • 31
  • 116
  • 182
91
votes
14 answers

How can I print the result of sizeof() at compile time in C?

How can I print the result of sizeof() at compile time in C? For now I am using a static assert (home brewed based on other web resources) to compare the sizeof() result to various constants. While this works... it is far from elegant or fast. I…
altendky
  • 4,176
  • 4
  • 29
  • 39
84
votes
5 answers

Is sizeof in C++ evaluated at compilation time or run time?

For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works? sizeof(short int)
ogzylz
  • 1,345
  • 2
  • 12
  • 13
72
votes
2 answers

When does a constexpr function get evaluated at compile time?

Since it is possible that a function declared as constexpr can be called during run-time, under which criteria does the compiler decide whether to compute it at compile-time or during runtime? template constexpr…
Byzantian
  • 3,208
  • 4
  • 27
  • 31
71
votes
2 answers

How to properly communicate compile-time information to Template Haskell functions?

I need to communicate some information from compile scripts into Template Haskell. Currently the compile scripts keep the information in the system environment, so I just read it using System.Environment.getEnvironment wrapped in runIO. Is there a…
Petr
  • 62,528
  • 13
  • 153
  • 317
64
votes
10 answers

Using std::map where V has no usable default constructor

I have a symbol table implemented as a std::map. For the value, there is no way to legitimately construct an instance of the value type via a default constructor. However if I don't provide a default constructor, I get a compiler error and if I make…
BCS
  • 75,627
  • 68
  • 187
  • 294
56
votes
4 answers

Simplest way to determine return type of function

Given a very simple, but lengthy function, such as: int foo(int a, int b, int c, int d) { return 1; } // using ReturnTypeOfFoo = ??? What is the most simple and concise way to determine the function's return type (ReturnTypeOfFoo, in this…
Cybran
  • 2,203
  • 2
  • 17
  • 34
45
votes
8 answers

Figure out function parameter count at compile time

I have a C library (with C headers) which exists in two different versions. One of them has a function that looks like this: int test(char * a, char * b, char * c, bool d, int e); And the other version looks like this: int test(char * a, char * b,…
Florian Bach
  • 919
  • 7
  • 22
42
votes
3 answers

Can I obtain C++ type names in a constexpr way?

I would like to use the name of a type at compile time. For example, suppose I've written: constexpr size_t my_strlen(const char* s) { const char* cp = s; while(*cp != '\0') { cp++; }; return cp - s; } and now I want to…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
2 3
61 62