I've used Swig to inherit from base classes in Java to implementations in C++. Swig generated the JNI and C++ bindings. Fun times.
Swig – Connect C/C++ programs with high-level programming languages
81–90 of 90 posts
Re: Swig – Connect C/C++ programs with high-level programming languages
#82Who classifies C++ as a low-level programming language? Even C is only being called low-level relatively recently, and it's not universally accepted as such.
You could argue IS NOT (high-level) does not necessarily imply IS (low-level), in which case no-one classified C++ as low-level. I guess for the large part the inter-op here is from (mostly) interpreted languages, which are certainly higher level than C++. Maybe instead of it being a binary choice between high-level and low-level languages, there is a middle ground. Fairly easy to argue that as the case.
There is: mid-level languages. I was taught (and still think of) C as a mid-level language; things like assembly are low-level languages; C++, Python, Java, etc., are all high-level languages.
But I'm a graybeard, and these are the meanings that I've learned. It's possible that the definitions have shifted and nobody told me.
Re: Swig – Connect C/C++ programs with high-level programming languages
#83Who classifies C++ as a low-level programming language? Even C is only being called low-level relatively recently, and it's not universally accepted as such.
If it requires explicitly allocating memory, then it is low level to most contemporary programmers.
I thought the "level" of a programming language was referring to the level of abstraction it presents rather than how memory allocation is performed. Low-level would be very close to machine language. C and C++ have very different levels of abstraction, for instance, and being able to express that seems useful.
Re: Swig – Connect C/C++ programs with high-level programming languages
#84Earlier quoted context omitted.
If it requires explicitly allocating memory, then it is low level to most contemporary programmers.
That doesn't seem like a useful dividing line, if only because it consigns a lot of different languages, with a very wide array of different levels of abstraction, as being "low level". That makes the term "low level" very nearly worthless. I thought the "level" of a programming language was referring to the level of abstraction it presents rather than how memory allocation is performed. Low-level would be very close…
Re: Swig – Connect C/C++ programs with high-level programming languages
#85Earlier quoted context omitted.
That doesn't seem like a useful dividing line, if only because it consigns a lot of different languages, with a very wide array of different levels of abstraction, as being "low level". That makes the term "low level" very nearly worthless. I thought the "level" of a programming language was referring to the level of abstraction it presents rather than how memory allocation is performed. Low-level would be very close…
A language and its libraries will inevitably allow a whole range of abstractions. Also, just about every piece of software has layers above and below. Hence my subjective qualification: "to most contemporary programmers" - to a bunch of which everything below the Javascript engine is low level !
True, but that's a different sort of "abstraction" than what I'm talking about. I'm talking about how abstracted the processor itself is. Libraries and the like don't really enter into it -- this is about the language proper.
Machine language has no abstraction whatsoever. What you write is literally the code that the CPU executes.
Assembly language is one higher level of abstraction. There's still mostly a 1 to 1 correspondence to machine language, but some of that gets hidden for human convenience. You're now writing with symbols instead of numeric op codes, and you have concepts like macros, which have no machine language equivalent.
C is a higher level than that. Every C statement can easily be expressed directly in assembly, but more common operations (loops, subroutines, etc) have a shorthand that makes them easier to write. There is no longer a 1 to 1 correspondence with assembly or machine language, but it's not terribly far from assembly. Still, it's abstracted enough that the language is no longer tied to a specific processor.
C++ is yet another level up the ladder. In a sense, C++ is to C what assembly is to machine language.
And so forth.
I suppose that a plausible (but highly imperfect) rule of thumb for how high up the ladder of abstraction a language sits is how many machine language instructions are required to implement a given language construct. The more required, the higher the level of abstraction. High level languages also have a lot more (indeed, mostly consist of) constructs that simply don't exist at the machine language level.
Re: Swig – Connect C/C++ programs with high-level programming languages
#86I used Swig to connect our C++ API to Ruby back in... '02 (wow, so 21 years ago, time flies!). It worked great. We could try things out in IRB (the Ruby REPL) and it allowed us to quickly write unit tests in Ruby (this was well before things like gtest). There are probably better/easier ways to do that now, but back then Swig was the only game in town and for us it worked out pretty well.
I thought I could leave it that way until one day a manager came and questioned why we had terrible unit test coverage. It turned out we had separate tools for measuring code coverage in C++ and Go and it was impossible to make them work together.
Re: Swig – Connect C/C++ programs with high-level programming languages
#87Earlier quoted context omitted.
I'd recommend pybind11 for c/c++ python bridge. Though you have to compile your wheel for every minor python version separately.
cibuildwheel ( https://cibuildwheel.readthedocs.io/en/stable/ ) makes this fairly straightforward.
Re: Swig – Connect C/C++ programs with high-level programming languages
#88I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).
The GNU Radio project dumped Swig and replaced it with pybind11 for the same reason. Just a nightmare when things go wrong.
Re: Swig – Connect C/C++ programs with high-level programming languages
#89Re: Swig – Connect C/C++ programs with high-level programming languages
#90I've used Swig for C++ to Python interop and let me warn you it is a nightmare. The syntax is absurdly terse and convoluted, documentation sucks and good luck trying to search the web for constructs made only of special characters. CLIF is way nicer for C++/Python. If you need other languages then best of luck (Zig, Rust and D are easier than Java and Go at least).