Why do ints defined in template mixins have garbage values?
    H. S. Teoh 
    hsteoh at quickfur.ath.cx
       
    Tue Dec 11 21:21:32 UTC 2018
    
    
  
P.S.  Just looked at the disassembly.  Seems to be a codegen bug -- the
code appears to be trying to lookup local variables (presumably i0 and
i1), but somehow the initialization code is missing.
--T
On Tue, Dec 11, 2018 at 09:09:55PM +0000, Johannes Riecken via Digitalmars-d-learn wrote:
> Code:
> 
> import std.conv;
> import std.stdio;
> 
> mixin template genInts()
> {
>   enum arr = [0,1];
>   static foreach (t; arr) {
>     mixin("int i" ~ to!string(t) ~ " = 5;");
>   }
> }
> 
> void main() {
>   mixin genInts!();
>   writeln(i0);
>   writeln(i1);
> }
> 
> 
> Expected output:
> 5
> 5
> 
> Actual output is two garbage integer values.
-- 
"If you're arguing, you're losing." -- Mike Thomas
    
    
More information about the Digitalmars-d-learn
mailing list