github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/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 char globalChar = 100; 12 void *globalVoidPtrSet = &global; 13 void *globalVoidPtrNull; 14 int64_t globalInt64 = -(2LL << 40); 15 collection_t globalStruct = {256, -123456, 3.14, 88}; 16 int globalStructSize = sizeof(globalStruct); 17 short globalArray[3] = {5, 6, 7}; 18 joined_t globalUnion; 19 int globalUnionSize = sizeof(globalUnion); 20 option_t globalOption = optionG; 21 bitfield_t globalBitfield = {244, 15, 1, 2, 47, 5}; 22 23 int cflagsConstant = SOME_CONSTANT; 24 25 int smallEnumWidth = sizeof(option2_t); 26 27 char globalChars[] = {2, 0, 4, 8}; 28 29 int fortytwo() { 30 return 42; 31 } 32 33 int add(int a, int b) { 34 return a + b; 35 } 36 37 int doCallback(int a, int b, binop_t callback) { 38 return callback(a, b); 39 } 40 41 int variadic0() { 42 return 1; 43 } 44 45 int variadic2(int x, int y, ...) { 46 return x * y; 47 } 48 49 void store(int value, int *ptr) { 50 *ptr = value; 51 } 52 53 void unionSetShort(short s) { 54 globalUnion.s = s; 55 } 56 57 void unionSetFloat(float f) { 58 globalUnion.f = f; 59 } 60 61 void unionSetData(short f0, short f1, short f2) { 62 globalUnion.data[0] = 5; 63 globalUnion.data[1] = 8; 64 globalUnion.data[2] = 1; 65 } 66 67 void arraydecay(int buf1[5], int buf2[3][8], int buf3[4][7][2]) { 68 // Do nothing. 69 }