Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different programming language and calling convention

According to the wiki:

Different programming languages use different calling conventions, and so can different platforms (CPU architecture + operating system). This can sometimes cause problems when combining modules written in multiple languages

So am I supposed to be careful when I call C/C++ functions (exported from .so/.dll) in Python? If yes, what should I be careful of?

like image 935
Alcott Avatar asked Jan 18 '23 13:01

Alcott


1 Answers

Calling between Python and C is a solved problem, so you generally won't have to worry about anything -- not least because Python is written in C.

The problem described there is more an issue when multiple languages on a platform are all developed independently, individually bootstrapped from assembler. For example, there used to famously be problems calling between C and FORTRAN, and between C and Pascal, at a time when all three of those languages coexisted as rough equals. The old Mac Toolbox was written mostly in assembler using Pascal calling conventions, and early application developers used Borland Pascal. But then C compilers like Symatec's THINK C appeared, and those programmers had to specifically worry about how to translate argument types and string conventions (Pascal strings carry a length byte at the beginning, and of course C strings have a 0 at the end.)

like image 86
Ernest Friedman-Hill Avatar answered Jan 27 '23 12:01

Ernest Friedman-Hill