digitalmars.D - C++ interop - class vs struct
- Walter Bright (6/6) Sep 10 2014 C++ name mangling distinguishes between a class and a struct. This disti...
- FreeSlave (11/18) Sep 10 2014 Just for clarification. I should notice it relates only to msvc
- Daniel Murphy (6/13) Sep 10 2014 pragma(cpp_mangle_as_struct)
- Lionello Lunesu (6/10) Sep 11 2014 and/or?
- Daniel Murphy (3/8) Sep 11 2014 Yeah. No need to add new syntax, and it means adding a way to make D li...
- Andrei Alexandrescu (2/17) Sep 11 2014 I think attributes would be the go-to approach. -- Andrei
- Daniel Murphy (3/4) Sep 11 2014 Why?
- Andrei Alexandrescu (2/6) Sep 11 2014 Because they postdate pragma :o). I'm fine either way. -- Andrei
C++ name mangling distinguishes between a class and a struct. This distinction has no semantic meaning, but there it is in the name mangling. In order to interop, we have to have a way to tell D to mangle a struct as a 'class' when interfacing with C++. I have some ideas, but they're all kinda ugly. Any ideas?
Sep 10 2014
On Wednesday, 10 September 2014 at 20:43:44 UTC, Walter Bright wrote:C++ name mangling distinguishes between a class and a struct. This distinction has no semantic meaning, but there it is in the name mangling. In order to interop, we have to have a way to tell D to mangle a struct as a 'class' when interfacing with C++. I have some ideas, but they're all kinda ugly. Any ideas?Just for clarification. I should notice it relates only to msvc mangling model, which does not respect equivalence of struct and class and use different symbols to mangle them (U and V). There is also warning C4099 because of it. g++ seems to use same mangling regardless of how you declare class (with class or struct keyword). Even if you find good solution by extending language (for example, by adding extern(C++-struct)) it would make sense only for Windows platforms.
Sep 10 2014
"Walter Bright" wrote in message news:luqd60$2u0r$1 digitalmars.com...C++ name mangling distinguishes between a class and a struct. This distinction has no semantic meaning, but there it is in the name mangling. In order to interop, we have to have a way to tell D to mangle a struct as a 'class' when interfacing with C++. I have some ideas, but they're all kinda ugly. Any ideas?pragma(cpp_mangle_as_struct) class Foo { } This is a low-level feature, and should be ugly.
Sep 10 2014
On 11/09/14 14:32, Daniel Murphy wrote:pragma(cpp_mangle_as_struct) class Foo { }and/or? pragma(cpp_mangle_as_class) struct Bar { }
Sep 11 2014
"Lionello Lunesu" wrote in message news:luriec$1081$1 digitalmars.com...and/or? pragma(cpp_mangle_as_class) struct Bar { }Yeah. No need to add new syntax, and it means adding a way to make D link with C++ rather than adding C++ features to D.
Sep 11 2014
On 9/10/14, 11:32 PM, Daniel Murphy wrote:"Walter Bright" wrote in message news:luqd60$2u0r$1 digitalmars.com...I think attributes would be the go-to approach. -- AndreiC++ name mangling distinguishes between a class and a struct. This distinction has no semantic meaning, but there it is in the name mangling. In order to interop, we have to have a way to tell D to mangle a struct as a 'class' when interfacing with C++. I have some ideas, but they're all kinda ugly. Any ideas?pragma(cpp_mangle_as_struct) class Foo { } This is a low-level feature, and should be ugly.
Sep 11 2014
"Andrei Alexandrescu" wrote in message news:lurk9p$123f$1 digitalmars.com...I think attributes would be the go-to approach. -- AndreiWhy?
Sep 11 2014
On 9/11/14, 12:57 AM, Daniel Murphy wrote:"Andrei Alexandrescu" wrote in message news:lurk9p$123f$1 digitalmars.com...Because they postdate pragma :o). I'm fine either way. -- AndreiI think attributes would be the go-to approach. -- AndreiWhy?
Sep 11 2014
On Thursday, 11 September 2014 at 07:58:14 UTC, Andrei Alexandrescu wrote:On 9/11/14, 12:57 AM, Daniel Murphy wrote:Those are different tools. Attributes are part of language semantics, pragmas are to work with compiler internals. It is not like we have `getPragmas` trait. I agree that this is better fit for a pragma."Andrei Alexandrescu" wrote in message news:lurk9p$123f$1 digitalmars.com...Because they postdate pragma :o). I'm fine either way. -- AndreiI think attributes would be the go-to approach. -- AndreiWhy?
Sep 11 2014
On Thursday, 11 September 2014 at 09:09:41 UTC, Dicebot wrote:On Thursday, 11 September 2014 at 07:58:14 UTC, Andrei Alexandrescu wrote:Also, there already is a pragma for controlling the mangling, so it'll be easier to extend it. Something like: extern (C++) pragma(mangle, struct) interface E { int bar(int i, int j, int k); }On 9/11/14, 12:57 AM, Daniel Murphy wrote:Those are different tools. Attributes are part of language semantics, pragmas are to work with compiler internals. It is not like we have `getPragmas` trait. I agree that this is better fit for a pragma."Andrei Alexandrescu" wrote in message news:lurk9p$123f$1 digitalmars.com...Because they postdate pragma :o). I'm fine either way. -- AndreiI think attributes would be the go-to approach. -- AndreiWhy?
Sep 11 2014