github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/testdata/cgo/main.h (about)

     1  #include <stdbool.h>
     2  #include <stdint.h>
     3  
     4  typedef short myint;
     5  typedef short unusedTypedef;
     6  int add(int a, int b);
     7  int unusedFunction(void);
     8  typedef int (*binop_t) (int, int);
     9  int doCallback(int a, int b, binop_t cb);
    10  typedef int * intPointer;
    11  void store(int value, int *ptr);
    12  
    13  int variadic0();
    14  int variadic2(int x, int y, ...);
    15  
    16  # define CONST_INT 5
    17  # define CONST_INT2 5llu
    18  # define CONST_FLOAT 5.8
    19  # define CONST_FLOAT2 5.8f
    20  # define CONST_CHAR 'c'
    21  # define CONST_STRING "defined string"
    22  
    23  // this signature should not be included by CGo
    24  void unusedFunction2(int x, __builtin_va_list args);
    25  
    26  typedef struct collection {
    27  	short         s;
    28  	long          l;
    29  	float         f;
    30  	unsigned char c;
    31  } collection_t;
    32  
    33  struct point2d {
    34  	int x;
    35  	int y;
    36  };
    37  
    38  typedef struct {
    39  	int x;
    40  	int y;
    41  } point2d_t;
    42  
    43  typedef struct {
    44  	int x;
    45  	int y;
    46  	int z;
    47  } point3d_t;
    48  
    49  typedef struct {
    50  	int tag;
    51  	union {
    52  		int a;
    53  		int b;
    54  	} u;
    55  } tagged_union_t;
    56  
    57  typedef struct {
    58  	int x;
    59  	struct {
    60  		char red;
    61  		char green;
    62  		char blue;
    63  	} color;
    64  } nested_struct_t;
    65  
    66  typedef union {
    67  	int x;
    68  	struct {
    69  		char a;
    70  		char b;
    71  	};
    72  } nested_union_t;
    73  
    74  // linked list
    75  typedef struct list_t {
    76  	int           n;
    77  	struct list_t *next;
    78  } list_t;
    79  
    80  typedef union joined {
    81  	myint s;
    82  	float f;
    83  	short data[3];
    84  } joined_t;
    85  void unionSetShort(short s);
    86  void unionSetFloat(float f);
    87  void unionSetData(short f0, short f1, short f2);
    88  
    89  typedef enum option {
    90  	optionA,
    91  	optionB,
    92  	optionC = -5,
    93  	optionD,
    94  	optionE = 10,
    95  	optionF,
    96  	optionG,
    97  } option_t;
    98  
    99  typedef enum {
   100  	option2A = 20,
   101  } option2_t;
   102  
   103  typedef enum {
   104  	option3A = 21,
   105  } option3_t;
   106  
   107  typedef struct {
   108  	unsigned char start;
   109  	unsigned char a : 5;
   110  	unsigned char b : 1;
   111  	unsigned char c : 2;
   112  	unsigned char :0; // new field
   113  	unsigned char d : 6;
   114  	unsigned char e : 3;
   115  	// Note that C++ allows bitfields bigger than the underlying type.
   116  } bitfield_t;
   117  
   118  // test globals and datatypes
   119  extern int global;
   120  extern int unusedGlobal;
   121  extern bool globalBool;
   122  extern bool globalBool2;
   123  extern float globalFloat;
   124  extern double globalDouble;
   125  extern _Complex float globalComplexFloat;
   126  extern _Complex double globalComplexDouble;
   127  extern _Complex double globalComplexLongDouble;
   128  extern char globalChar;
   129  extern void *globalVoidPtrSet;
   130  extern void *globalVoidPtrNull;
   131  extern int64_t globalInt64;
   132  extern collection_t globalStruct;
   133  extern int globalStructSize;
   134  extern short globalArray[3];
   135  extern joined_t globalUnion;
   136  extern int globalUnionSize;
   137  extern option_t globalOption;
   138  extern bitfield_t globalBitfield;
   139  
   140  extern int smallEnumWidth;
   141  
   142  extern int cflagsConstant;
   143  
   144  extern char globalChars[4];
   145  
   146  // test duplicate definitions
   147  int add(int a, int b);
   148  extern int global;
   149  
   150  // Test array decaying into a pointer.
   151  typedef int arraydecay_buf3[4][7][2];
   152  void arraydecay(int buf1[5], int buf2[3][8], arraydecay_buf3 buf3);