https://d.puremagic.com/issues/show_bug.cgi?id=12308
--- Comment #2 from Adam D. Ruppe <[email protected]> 2014-03-07 07:18:14 PST --- I don't think it has been explained fully yet. A struct with just an int is not fully interchangeable for an int because they are returned differently by functions, including in C. So this isn't really a matter of fixing anything, since it isn't broken, it is a different spec. indeed, since it changes the calling convention, how would this mangle? I'd say the same as the type it wraps. The struct just disappears as far as the backend is concerned. A few other points in the thread: couldn't the hidden this be changed to pass by value? Maybe, though taking the address of this wouldn't work, I think. A* ptr() { return &this; } works now, just returning EAX (which is the hidden this pointer in the first place). Trying that with a regular int is (awesomely!) an error: int* foo(int a) { return &a; } test56.d(17): Error: escaping reference to local a * * * Could we just change the D calling convention to pass small structs by value* while keeping extern(C) the same for compatibility? Yes, I think we can, and I think it would be a win. But I'd still like it to be available in extern(C) too for cases like library typedef, where we want it to look different on the D side, but remain ABI identical to the naked type. * Note: this is already what happens for most function arguments: void test(A a); calling that looks like: mov EAX, [a]; call test; Which is identical to test(int a). The difference is returning a value and the hidden this pointer. Returning a value is done by hidden pointer too. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
