[Issue 5337] New: DMD compiles incorrect code on windows

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 9 08:51:51 PST 2010


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

           Summary: DMD compiles incorrect code on windows
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: CrypticMetaphor88 at gmail.com


--- Comment #0 from CrypticMetaphor88 at gmail.com 2010-12-09 08:50:08 PST ---
Created an attachment (id=845)
Compiling and running in windows command prompt

Code that should not compile, imported from C, compiles on windows, but does
NOT compile on Linux.

Here the example:
// cfile.c file
extern int globalFromD;

void functionFromC(int a) {
   globalFromD = a;
}
// end cfile.c

// dfile.d
extern(C) { // this is needed to make it available from C
        int globalFromD;
}
extern(C) { // also needed when listing the prototypes for your C functions
        void functionFromC(int);
}

import std.stdio; // for writefln

int main() {
        globalFromD = 100;
        writefln("%d", globalFromD);

        functionFromC(500);
        writefln("%d", globalFromD);

        return 0;
}
// end dfile.d

I compile with:
dmc -c cfile.c
And I get  an cfile.obj, which is the object code (.o in gcc).
Then I compile the D code
dmd dfile.d cfile.obj
and I get no errors, so I run it, the result:
// start result
C:\DCode\libtest>dfile.exe
100
100

C:\DCode\libtest>
// end result 

I've posted this on the newsgroup( d.D.learn, Subject:"Calling C functions" )
and apparently it's some kind of bug.

More info:

dmc version: 8.42n
dmd version: 2.050

Windows version: Windows XP.

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


More information about the Digitalmars-d-bugs mailing list