www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2237] New: string mixin + const array = array literal constructed upon every use (??!?!)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2237

           Summary: string mixin + const array = array literal constructed
                    upon every use (??!?!)
           Product: D
           Version: 1.031
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


Oh, DMDFE, what am I ever going to do with you.

const int[] arr = mixin("[5, 6]");

void main()
{
        int f = 0;
        int y = arr[f]; // make sure it's a non-constant index
}

If you look at the generated code, it actually inserts the dynamic array
literal [5, 6] EVERYWHERE 'arr' IS USED.  So it's more like you do:

int y = [5, 6][f];

If you change the declaration of 'arr' to be a mixin declaration instead:

mixin("const int[] arr = [5, 6];");

It actually puts the array in the static data segment and accesses it from
there, like it should.


-- 
Jul 19 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2237


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 2356 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2237


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |verylonglogin.reg gmail.com
         Resolution|DUPLICATE                   |



---
Is it really a duplicate? issue 2356 doesn't mention string mixins or any other
initializer dependencies. Why
---
const int[] arr = mixin("[5, 6]");
---
behaves differ from
---
mixin("const int[] arr = [5, 6];");
---
?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2237




Hmm, I think I must have put the wrong bug number in.  I think this is a
duplicate of the D1 version of bug 2414.  Now if only I could find the actual
bug... (I can only find that one because I know it has 'yum' in the title.) 
Glad somebody is checking.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2012