To be clear I want to send my C function an array of null strings of fixed length like:
[“”, “”, “”]
expect the array to return populated like:
[“1.2345”, “6.7891”, “0.1112”]
I’ve attached the GMP library to an Xcode Project and wanted to test out some functionality by sending an array of inputs, and read out an array of outputs. I just can’t seem to figure out how to pass out an array of char* from C to Swift.
The error indicates I need a specific format. I’ve seen examples of just one char* but not an array of them and I can’t fathom from that the correct way I construct a proper unsafe pointer for an array.
my C header
#define GMP_STR_MAXLEN 256
void get_gmp_calculations(const signed long int inputs_x[], const signed long int inputs_y[], int inputs_len, char *outputs[]);
my Swift code
func test_gmp(int_inputs_x: [Int], int_inputs_y: [Int])
{
var outputs: [[CChar]] = [[CChar]](repeating: [CChar](repeating: 0, count: Int(GMP_STR_MAXLEN)), count: int_inputs_x.count)
var unsafe_outputs: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>? = //??? something something "outputs"
get_gmp_calculations(int_inputs_x, int_inputs_y, Int32(int_inputs_x.count), unsafe_outputs)