Forum > General
C/C++ Interop, RTTI From C/C++
guest60499:
Hello,
Has this ever been considered or has any work ever been done on it?
The main usecase I can see is taking an existing C++ codebase and making it usable with FPC.
However I do also have some interest in using the LCL from C++. I see other people benefiting from this as well; the LCL pops up from time to time on programming forums as the best cross platform toolkit. (It is.)
Cheers,
guest
marcov:
Well, the first problem is that there is no "C++" abi to interface. Every C++ compiler has its own rules wrt mangling and other details.
The easiest way to do this is to also have a Free C++ compiler and keep it strictly aligned to FPC. (more or less like Embacadero does with C++ builder and Delphi)
guest60499:
--- Quote from: marcov on August 02, 2018, 06:15:52 pm ---Well, the first problem is that there is no "C++" abi to interface. Every C++ compiler has its own rules wrt mangling and other details.
--- End quote ---
Right, this is what I was hoping someone had a solution to. It looks like Rust provides a library for demangling LLVM names. I'm not sure how good an idea this ultimately is.
--- Quote from: marcov on August 02, 2018, 06:15:52 pm ---The easiest way to do this is to also have a Free C++ compiler and keep it strictly aligned to FPC. (more or less like Embacadero does with C++ builder and Delphi)
--- End quote ---
Well, if that is indeed the best solution I do not see it happening very soon.
Easier might be to provide a linkage block compatible with FPC and its RTTI. This was at one point done for Java via GCJ and 'extern "Java"'.
Another might be exposing "class" information in C linkage blocks. This is why I had been asking about COM/GObject, though I think FreePascal could do far better than either.
Hopefully it can be seen that these two are kind of related.
What about using FPC code from C/C++ without shoving everything through a dynamic library?
marcov:
--- Quote from: guest on August 03, 2018, 07:13:32 pm ---
--- Quote from: marcov on August 02, 2018, 06:15:52 pm ---Well, the first problem is that there is no "C++" abi to interface. Every C++ compiler has its own rules wrt mangling and other details.
--- End quote ---
Right, this is what I was hoping someone had a solution to. It looks like Rust provides a library for demangling LLVM names. I'm not sure how good an idea this ultimately is.
--- End quote ---
All hypothetically feasible, but difficult in practice.
--- Quote from: marcov on August 02, 2018, 06:15:52 pm ---The easiest way to do this is to also have a Free C++ compiler and keep it strictly aligned to FPC. (more or less like Embacadero does with C++ builder and Delphi)
--- End quote ---
Well, if that is indeed the best solution I do not see it happening very soon.
Easier might be to provide a linkage block compatible with FPC and its RTTI. This was at one point done for Java via GCJ and 'extern "Java"'.
[/quote]
What is a "linkage block" ?
--- Quote ---Another might be exposing "class" information in C linkage blocks. This is why I had been asking about COM/GObject, though I think FreePascal could do far better than either.
--- End quote ---
I don't know what C linkage blocks are. You can write a C library that can parse FPC rtti.
COM and afaik GOBject doesn't work on RTTI level. You call functions to get info, and you can rewire them to whatever your implementation is.
--- Quote ---Hopefully it can be seen that these two are kind of related.
--- End quote ---
Well, COM is more interprocess and about interoperability. GObject is just a library for languages that don't have a proper object model. Just start playing with it. As said you might be able to wrap a IDispatch interface around a gobject base class, and then be able to use it dynamically.
--- Quote ---What about using FPC code from C/C++ without shoving everything through a dynamic library?
--- End quote ---
You can try. But in practice that is again through a procedural interface only.
A lot is easy to do for isolated cases. It is hard to do something that is universal wrt various targets, various languages and not reducing any of the languages involved to the lowest common denominator (read: sacrifice either C++ standard compliance or FPC Delphi compatibility)
There are few people working on this, so I guess it is just waiting for sb interested to get into it.
guest60499:
Sorry, a linkage block looks like:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---extern "C" { void exported_function(void); }
The only valid string is typically "C" but GCC has supported one nontraditional one, "Java," which created virtual method tables that would interop. with GCC's now defunct Java compiler.
I only now remembered it, it may be the best way to go from C++ -> FPC.
Is there any code available that shows parsing the RTTI from C? Ideally I'm wanting to get everything but COM working (I don't care too much for Windows, and it already half-works) but for one person it is definitely a multiyear project.
Navigation
[0] Message Index
[#] Next page