[Issue 832] New: Struct copying changed in 1.0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 12 02:36:33 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=832

           Summary: Struct copying changed in 1.0
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: alan at akbkhome.com


The behaviour changed in dmd-0.178 such that foreach on an array of structs
only appears to do  a shallow copy, rather than a deep copy.

output of the code below is 29/30 or <.178, and a random number on 178/1.0.

import std.stdio;

const char[] XML_PUBLIC_ID_SYNCML_SYNCML11 ="-//SYNCML//DTD SyncML 1.1//EN";


struct WBXMLPublicIDEntry {
                int  wbxmlPublicID;     /**< WBXML Public ID */
                char[] xmlPublicID; /**< XML Public ID */
                char[] xmlRootElt;  /**< XML Root Element */
                char[] xmlDTD;      /**< XML DTD */
        }               

const WBXMLPublicIDEntry sv_wml11_public_id           = { 
        33,              
        XML_PUBLIC_ID_SYNCML_SYNCML11,            
        "wml",                  
        "http://www.wapforum.org/DTD/wml.xml"               
};

        struct WBXMLLangEntry
        {
                int               langID;             /**< Language ID */
                WBXMLPublicIDEntry    publicID;          /**< Public ID */
        }       


const WBXMLLangEntry mainTable[] = [

        { 123,             
                sv_wml11_public_id },

        { 132,              sv_wml11_public_id }
];

void main()
{
         WBXMLLangEntry mt = getfirst();
         WBXMLPublicIDEntry pie = getName(mt);

         writefln("got %d", pie.xmlPublicID.length);
}
static WBXMLLangEntry getfirst()
{

        foreach(mt;mainTable) {
                return mt;
        }
}
WBXMLPublicIDEntry getName(WBXMLLangEntry mt) 
{
        return mt.publicID;
}


-- 



More information about the Digitalmars-d-bugs mailing list