Returning Typed Pointer From Swift to C++

See this ancient post by @eskimo.

Basically, you declare the struct in C and import it into Swift.

@main
enum CallC {
    static func main () {
        var b = bar (value: 7)
        print_bar (b)
        print (b)
        mutate_bar (&b)
        print (b)
    }
}
print_bar 7
bar(value: 7)
mutate_bar 7
bar(value: 13)
// Bridging-Header.h
//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#include "C.h"

//  C.h

#ifndef C_h
#define C_h


struct bar {
    long value;
};

void print_bar (const struct bar);
void mutate_bar (struct bar*);

#endif /* C_h */

//  C.c

#include <stdio.h>
#include "C.h"

void print_bar (const struct bar v) {
    printf ("%s %ld\n", __func__, v.value);
}
void mutate_bar (struct bar *pv) {
    printf ("%s %ld\n", __func__, pv->value);
    pv->value = 13;
}

Similarly for C++, but you export the C++ functions as C functions.