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
17
votes
12 answers

error: unable to spawn process (Argument list too long) in Xcode Build

I am getting this error: "error: unable to spawn process (Argument list too long) ** ARCHIVE FAILED ** The following build commands failed: CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (1 failure) Exitcode =65 " I…
Falguni
  • 181
  • 1
  • 1
  • 4
17
votes
1 answer

Does creating a (non-list) data structure via fromList actually create the list?

Essentially I'm curious if code like: let myCollection = Data.SomeCollection.fromList [1, 2, foo] is actually doing what it looks like at runtime, and creating a linked list as an intermediate step in creating a SomeCollection—or if this is just a…
J Cooper
  • 16,891
  • 12
  • 65
  • 110
17
votes
6 answers

Compile time prime checking

I need to check is some integer prime in compile time (to put the boolean value as template argument). I've write code that do it well: #include namespace impl { template struct PrimeChecker { …
RiaD
  • 46,822
  • 11
  • 79
  • 123
17
votes
4 answers

Compile-time population of data structures other than arrays?

In C++, you can do this: static const char * [4] = { "One fish", "Two fish", "Red fish", "Blue fish" }; ... and that gives you a nice read-only array data-structure that doesn't take any CPU cycles to initialize at runtime, because all…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
16
votes
4 answers

Encrypting / obfuscating a string literal at compile-time

I want to encrypt/encode a string at compile time so that the original string does not appear in the compiled executable. I've seen several examples but they can't take a string literal as argument. See the following example: template struct…
karliwson
  • 3,365
  • 1
  • 24
  • 46
16
votes
1 answer

Compile time check AND runtime check 'at the same time'

Suppose I have the following simplified program: Link to godbolt.org: #include struct Dimensions { Dimensions& operator=(int i) { assert(i != 0); return *this; } }; int getDim(); int main() { Dimensions dims; …
darune
  • 10,480
  • 2
  • 24
  • 62
16
votes
4 answers

What are 'constexpr' useful for?

I really can't find any use of it. My first idea was that I could use it to implement 'Design by Contract' without using macros like this: struct S { S(constexpr int i) : S(i) { static_assert( i < 9, "i must be < 9" ); } S(int i);…
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
16
votes
3 answers

compile-time function for checking type equality

I need to implement self contained compile-time function for checking type equality (function template without arguments bool eqTypes()). self contained means not relying on library. I'm not good in all this. That's what I tried, but it's not…
Roman2452809
  • 378
  • 1
  • 2
  • 17
15
votes
6 answers

Extracting Property Names For Reflection, with Intellisense and Compile-Time Checking

Ok. So I have some code that maps certain controls on a winForm to certain properties in an object, in order to do certain things to the controls when certain things happen to the data. All well and good, works fine. Not the problem. The issue…
GWLlosa
  • 23,995
  • 17
  • 79
  • 116
15
votes
2 answers

Flutter: make build-time environment variables available to code

How can I have build-time environment variables available to code within a Flutter app? (My specific use case is to inject app version number and commit hash into a debug screen. This information is available at build time, but not at runtime). I…
Matt R
  • 9,892
  • 10
  • 50
  • 83
15
votes
3 answers

Checking whether an object conforms to two separate protocols in Objective-C

In Objective-C when you declare an instance variable you can check if it conforms to a protocol on assignment at compile time like so: id variable; Is it possible to check whether an object assigned to the variable conforms to two…
Jasarien
  • 58,279
  • 31
  • 157
  • 188
15
votes
1 answer

In Common Lisp, when do you need to use eval-when, and how do you know?

A required use of eval-when is to ensure that functions which a macro depends on are available at the time the macro is compiled and is used. However, I can't think of an example that would demonstrate the consequences of not using…
anticrisis
  • 918
  • 1
  • 8
  • 17
15
votes
6 answers

Do math functions of constant expressions get pre-calculated at compile time?

I tend to use math functions of constant expressions for convinience and coherence (i.e log(x)/log(2) instead of log(x)/0.3...). Since these functions aren't actually a part of the language itself, neither are they defined in math.h (only declared),…
cvb
  • 4,321
  • 6
  • 26
  • 19
15
votes
2 answers

C# Compile-Time Concatenation For String Constants

Does C# do any compile-time optimization for constant string concatenation? If so, how must my code by written to take advantage of this? Example: How do these compare at run time? Console.WriteLine("ABC" + "DEF"); const string s1 =…
Joseph Sturtevant
  • 13,194
  • 12
  • 76
  • 90
15
votes
2 answers

Confusion about constant expressions

This is some kind of follow-up for this topic and deals about a little part of it. As with the previous topic, let's consider that our compiler has constexpr functions for std::initializer_list and std::array. Now, let's go straight to the…
Morwenn
  • 21,684
  • 12
  • 93
  • 152