Brad Roberts escribió:
Brad Roberts wrote:
Ary Borenszweig wrote:
Bill Baxter escribió:
Another question -- I was wondering what it does for CTFE functions.
I'm guessing it evaluates them and spits out the result. If so that
could be very very helpful. Especially for code-building CTFE mixins.
I don't think you had an example like that in the vid.
It does! See the first part of the video, when I do:
int x = 1 + 2 + 3 + 4 + someFunc(5);
and it shows:
int x = 25;
It just evaluated someFunc. :-)
Given that int x isn't a const expression, is someFunc(5) supposed to be
evaluated at compile time like that?
Later,
Brad
Hrm.. unless it's just bog standard inlining and const folding going on,
which is quite possible.
Great observation! I remember functions like that not being evaluated
unless the variable was declared const. I just debugged that and checked
with DMD's source code, and it seems the expression in the initializer
is evaluated if the variable declaration is not inside a function (check
VarDeclaration::semantic2 and ExpInitializer::semantic, which invoked
optimize at the end).
I wonder why is that behaviour defined like that...
Nevermind,
Brad