How to create and pass a 128 bit variable from Chapel program to third-party C library?

111 Views Asked by At

I need to call a method from a third-party C library in my Chapel application, which requires a 128 bit integer variable to be passed by value. Chapel does not have a native 128 bit integral type defined, other than complex(128), which is a combination of 2 64 bit real types. If I was calling this method from a C/C++ program I could have used "long long" to passed it.

How do I create a 128 bit integral type (or equivalent) in Chapel and pass it to the third-party C library method from my Chapel program?

1

There are 1 best solutions below

1
Brad On

@Rinjo —

Assuming that Chapel does not need to understand the meaning of the 128-bit value directly itself, you should be able to define it as an external type using something like:

extern type int128;  // or whatever type alias you might be able to use to
                     // refer to it in C

and then declare internal or external variables of that type using:

var chapelInt128: int128;
extern var cInt128: int128;

or pass such values between Chapel and C using things like:

extern proc getInt128FromC(): int128;  // a C routine returning int128s

export proc takeInt128FromC(x: int128) { ... } // a Chapel routine accepting int128s

If you're not already familiar with these features, you can learn more about them here: