Hi Sam,

I’m afraid you are misunderstanding SWIG.   Swig generates language bindings 
from C and C++ code.

It does this by creating a pure “C” wrapper for the code that is being wrapped. 
 I.e. exactly the kind of thing you are proposing.

After creating this export library, it then creates an import library on the 
“other language” side that loads the export library and maps it to the 
constructs of the target language.  In other words, it implements the full 
hourglass pattern in a semi-automated fashion.

For example, I use SWIG daily for bridging my C++ library to my C# .net 
applications, and even better, it works fully cross-platform too.  I get full 
(and smart) access to my STL containers, my C++ template programming, my 
classes and methods, and all I have to do is maintain a fairly simple SWIG 
interface file that controls the code-generation.

I’m not saying that SWIG is an out-of-the-box solution.  I’m just saying that 
SWIG has solved the problem you are discussing, and it’s probably worth at 
least seeing how it has dealt with the issues of pointers (for example, pointer 
parameters are not solved in SWIG because it’s an awfully difficult problem), 
object ownership and destruction, generating all the necessary template 
instances, etc.  Of course no modern solution would follow the SWIG approach of 
writing your own C++ parser, but for what it is, it works pretty well.

Mark

From: samuel ammonius <[email protected]>
Sent: 12 September 2022 21:44
To: Mark De Wit <[email protected]>; [email protected]
Subject: Re: [EXTERNAL EMAIL] [Development] Could support for C be added to Qt?

Hi Mark,

I don't think SWIG supports generating C from C++ or vice versa. Its website 
says
it can parse to XML, but that might not be very useful since Qt is so strict on 
its
code style rules<https://wiki.qt.io/Qt_Coding_Style>.

About the hourglass pattern, I'll put features that require more recent 
versions of C
inside #ifdef statements so that older versions of C can still use the library, 
but it will
mean that versions before C11 will have to type the full names of overloaded 
functions,
which will look like this:

QPushButton_new_QIcon_QString_QObject(myicon, mystr, mywindow);
_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to