github.com/aykevl/tinygo@v0.5.0/testdata/cgo/main.c (about)

     1  #include "main.h"
     2  
     3  int global = 3;
     4  _Bool globalBool = 1;
     5  _Bool globalBool2 = 10; // test narrowing
     6  float globalFloat = 3.1;
     7  double globalDouble = 3.2;
     8  _Complex float globalComplexFloat = 4.1+3.3i;
     9  _Complex double globalComplexDouble = 4.2+3.4i;
    10  _Complex double globalComplexLongDouble = 4.3+3.5i;
    11  collection_t globalStruct = {256, -123456, 3.14, 88};
    12  int globalStructSize = sizeof(globalStruct);
    13  short globalArray[3] = {5, 6, 7};
    14  joined_t globalUnion;
    15  int globalUnionSize = sizeof(globalUnion);
    16  
    17  int fortytwo() {
    18  	return 42;
    19  }
    20  
    21  int add(int a, int b) {
    22  	return a + b;
    23  }
    24  
    25  int doCallback(int a, int b, binop_t callback) {
    26  	return callback(a, b);
    27  }
    28  
    29  void store(int value, int *ptr) {
    30  	*ptr = value;
    31  }
    32  
    33  void unionSetShort(short s) {
    34  	globalUnion.s = s;
    35  }
    36  
    37  void unionSetFloat(float f) {
    38  	globalUnion.f = f;
    39  }
    40  
    41  void unionSetData(short f0, short f1, short f2) {
    42  	globalUnion.data[0] = 5;
    43  	globalUnion.data[1] = 8;
    44  	globalUnion.data[2] = 1;
    45  }