Compile time vs run time -- what is the difference?

Steven Schveighoffer schveiguy at gmail.com
Wed Dec 28 02:47:19 UTC 2022


On 12/27/22 9:31 PM, thebluepandabear wrote:
> I am reading through the free book on learning D by Ali Çehreli and I am 
> having difficulties understanding the difference between compile time 
> execution and run time execution in D language.

Compile time execution is running your code being compiled *while being 
compiled*. It allows you to generate compile-time data without having to 
write specialized "compile time only" constructs like templates or 
explicitly marked functions (as other languages typically do).

Compile time data doesn't consume any runtime to execute, it's already 
done by the time your binary is running. It also is usable *at compile 
time*, for things like `static if`, or `mixin`.

The intermediate language being executed is the parsed and semantically 
analyzed AST nodes.

-Steve



More information about the Digitalmars-d-learn mailing list