www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why can't compile time expressions do ___?

reply cy <dlang verge.info.tm> writes:
I'm not clear on why you aren't allowed to allocate memory with 
compile time execution, or why access to the filesystem is 
restricted. (Unless you pass -J/ I think?)
Feb 06 2016
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 6 February 2016 at 22:13:55 UTC, cy wrote:
 I'm not clear on why you aren't allowed to allocate memory with 
 compile time execution
You can... use the built-in new operator or arrays, etc.
 or why access to the filesystem is restricted. (Unless you pass 
 -J/ I think?)
CTFE is a "pure" environment, it is supposed to only depend on the code and passed compile options (which may indeed include a path with -J that you are allowed to read files from). It doesn't actually run a complete program on the installed computer / OS, it just does some computations. This is meant to be a security thing (which IMO is dubious) and a platform issue: D code can be compiled independently of an operating system.
Feb 06 2016