The relevant C code can be found in the willUseGo.c source file, which will be presented in two parts. The first part of willUseGo.c is as follows:
#include <stdio.h> #include "usedByC.h" int main(int argc, char **argv) { GoInt x = 12; GoInt y = 23; printf("About to call a Go function! "); PrintMessage();
If you already know C, you should understand why you need to include usedByC.h. This is the way that the C code knows about the available functions of a library.
The second part of the C program follows next:
GoInt p = Multiply(x,y); printf("Product: %d ",(int)p); printf("It worked! "); return 0; }
The GoInt p variable is needed for getting an integer value from a Go function, which is converted to a C integer using the (int) p notation.
Compiling and executing willUseGo.c on a macOS High Sierra machine will create the following output:
$ gcc -o willUseGo willUseGo.c ./usedByC.o $ ./willUseGo About to call a Go function! A Go function! Product: 276 It worked!