github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/struct.c (about)

     1  // Tests for structures.
     2  
     3  #include "tests.h"
     4  #include <stdio.h>
     5  
     6  typedef void function_t(int args);
     7  
     8  struct programming {
     9      float constant;
    10      char* pointer;
    11  };
    12  
    13  void pass_by_ref(struct programming* addr)
    14  {
    15      char* s = "Show string member.";
    16      float v = 1.23 + 4.56;
    17  
    18      addr->constant += 4.56;
    19      addr->pointer = s;
    20  
    21      is_eq(addr->constant, v);
    22      is_streq(addr->pointer, "Show string member.");
    23  }
    24  
    25  void pass_by_val(struct programming value)
    26  {
    27      value.constant++;
    28  
    29      is_eq(value.constant, 2.23);
    30      is_streq(value.pointer, "Programming in Software Development.");
    31  }
    32  
    33  /**
    34   * text
    35   */
    36  typedef struct mainStruct {
    37      double constant;
    38  } secondStruct;
    39  
    40  /*
    41   * Text
    42   */
    43  typedef struct {
    44      double t;
    45  } ts_c;
    46  
    47  // Text
    48  typedef struct ff {
    49      int v1, v2;
    50  } tt1, tt2;
    51  
    52  // Text1
    53  // Text2
    54  struct outer {
    55      int i;
    56      struct z {
    57          int j;
    58      } inner;
    59  };
    60  
    61  struct xx {
    62      int i;
    63      /**
    64  	 * Text
    65  	 */
    66      struct yy {
    67          int j;
    68          struct zz {
    69              int k;
    70          } deep;
    71      } inner;
    72  };
    73  
    74  /**
    75   * Some function
    76   */
    77  int summator(int i, float f)
    78  {
    79      return i + (int)(f);
    80  }
    81  
    82  typedef struct J J;
    83  struct J {
    84      float f;
    85      int (*fu)(J* j, float i);
    86  };
    87  
    88  int j_function(J* j, float i)
    89  {
    90      if (j != NULL) {
    91          return (int)(i + (*j).f);
    92      }
    93      return -1;
    94  };
    95  
    96  void struct_with_rec_fuction()
    97  {
    98      J j;
    99      j.f = 5.0;
   100      j.fu = j_function;
   101      is_eq(j.fu(&j, 4.0), 9);
   102      is_eq(j_function(NULL, 4.0), -1);
   103  }
   104  
   105  struct FinFinS {
   106      double d;
   107      int (*f)(int (*)(int));
   108  };
   109  
   110  int FinF1(int a)
   111  {
   112      return a + 1;
   113  }
   114  
   115  int FinF2(int (*f)(int))
   116  {
   117      int g = 45;
   118      return f(g);
   119  }
   120  
   121  void func_in_func_in_struct()
   122  {
   123      diag("function in function in struct");
   124      struct FinFinS ffs;
   125      ffs.f = FinF2;
   126      int res = ffs.f(FinF1);
   127      is_eq(res, 46);
   128  };
   129  
   130  struct info {
   131      struct deep_info {
   132          int a, b, c;
   133      } con;
   134      struct star_deep_info {
   135          int sa, sb, sc;
   136      } * star_con;
   137  };
   138  
   139  void struct_in_struct_with_star()
   140  {
   141      diag("struct in struct with star");
   142      struct info in;
   143  
   144      in.con.a = 45;
   145      is_eq(in.con.a, 45);
   146  
   147      struct star_deep_info st;
   148      in.star_con = &st;
   149  
   150      in.star_con->sa = 45;
   151      is_eq(in.star_con->sa, 45);
   152  
   153      struct info in2;
   154  
   155      struct star_deep_info st2;
   156      in2.star_con = &st2;
   157  
   158      in2.star_con->sa = 46;
   159      is_eq(in2.star_con->sa, 46);
   160      is_eq(in.star_con->sa, 45);
   161  }
   162  
   163  struct {
   164      int a;
   165  } m;
   166  typedef double** y;
   167  
   168  struct {
   169      int aa;
   170  } mm;
   171  typedef double** yy;
   172  
   173  struct mmm {
   174      int aaa;
   175  };
   176  typedef double*** yyy;
   177  
   178  struct mmmm {
   179      int aaaa;
   180  };
   181  typedef double**** yyyy;
   182  
   183  struct mmmmm0 {
   184      int aaaaa;
   185  } mmmmm;
   186  typedef double** yyyyy;
   187  
   188  typedef struct {
   189      int st1;
   190  } st2;
   191  typedef double** st3;
   192  
   193  typedef struct st4 {
   194      int st5;
   195  } st6;
   196  typedef double** st7;
   197  struct st4 st7a;
   198  
   199  typedef struct st4a {
   200      int st5a;
   201  } * st6a;
   202  
   203  typedef struct st4b {
   204      int st5b;
   205  }* const* st6b;
   206  
   207  struct st8 {
   208      int st9;
   209      struct st10 {
   210          int st11;
   211      };
   212  };
   213  typedef double** st12;
   214  
   215  struct st13 {
   216      int st14;
   217      struct st16 {
   218          int st17;
   219      } st18;
   220  } st19;
   221  typedef double** st20;
   222  
   223  typedef struct st21 {
   224      int st22;
   225      struct st23 {
   226          int st24;
   227      } st25;
   228  } st26;
   229  typedef double** st27;
   230  
   231  static struct unix_syscall {
   232      const char* zName;
   233  } aSyscall[] = {
   234      { "open" },
   235      { "close" }
   236  };
   237  
   238  struct memory {
   239      int* one;
   240      float** oop;
   241      double* two;
   242      struct memory* mm;
   243  };
   244  
   245  typedef double** subseg;
   246  
   247  struct mesh {
   248      subseg* dummysub;
   249  };
   250  
   251  double* returner(int* const* i, double* d)
   252  {
   253      (void)(i);
   254      return d;
   255  }
   256  
   257  void struct_null()
   258  {
   259      struct memory dm;
   260      float o = 99;
   261      float* oo = &o;
   262      float** ooo = &oo;
   263      dm.oop = ooo;
   264      struct memory* m = &dm;
   265      m->one = (int*)(NULL);
   266      m->two = (double*)(NULL);
   267      m->mm = (struct memory*)(NULL);
   268      m->one = (void*)(NULL);
   269      m->two = (void*)(NULL);
   270      m->mm = (void*)(NULL);
   271      *(m->oop) = (int*)NULL;
   272      (m->oop) = (int*)NULL;
   273      (void)(dm);
   274      (void)(m);
   275  
   276      (void)summator(1, 34.4);
   277      (void)returner(0, 0);
   278      double fd = 56;
   279      returner(0, &fd);
   280      (void)(fd);
   281  
   282      static const struct {
   283          const char* zPattern;
   284          const char* zDesc;
   285      } aTrans[] = {
   286          { "rchar: ", "Bytes received by read():" },
   287          { "wchar: ", "Bytes sent to write():" },
   288          { "syscr: ", "Read() system calls:" },
   289          { "syscw: ", "Write() system calls:" },
   290          { "read_bytes: ", "Bytes read from storage:" },
   291          { "write_bytes: ", "Bytes written to storage:" },
   292          { "cancelled_write_bytes: ", "Cancelled write bytes:" },
   293      };
   294  
   295      is_eq(strlen(aTrans[3].zPattern), 7);
   296      is_streq(aTrans[2].zPattern, "syscr: ");
   297      is_streq(aTrans[1].zDesc, "Bytes sent to write():");
   298  
   299      double d = 99;
   300      double* dd = &d;
   301      double** ddd = &dd;
   302      *(ddd) = (int*)NULL;
   303      (void)(ddd);
   304  
   305      struct memorypool {
   306          int** nowblock;
   307      };
   308      struct memorypool Vpool;
   309      int nowblock;
   310      int* s_nowblock = &nowblock;
   311      Vpool.nowblock = &s_nowblock;
   312      is_not_null(*Vpool.nowblock);
   313      *(Vpool.nowblock) = NULL;
   314      struct memorypool* pool = &Vpool;
   315      if (*(pool->nowblock) == (int*)NULL) {
   316          pass("ok");
   317      }
   318  
   319      mm.aa = 42;
   320      is_eq(mm.aa, 42);
   321  
   322      struct mesh msh;
   323      subseg sub[10];
   324      for (int i = 0; i < 10; i++) {
   325          sub[i] = (subseg)(ddd);
   326      }
   327      msh.dummysub = sub;
   328      struct mesh* ms = &msh;
   329      ms->dummysub[2] = (subseg)NULL;
   330      (void)(ms);
   331      pass("ok");
   332  }
   333  
   334  union STRS {
   335      double d;
   336      struct {
   337          double d;
   338      } T;
   339  };
   340  
   341  void struct_inside_union()
   342  {
   343      union STRS s;
   344      s.T.d = 10.0;
   345      is_true(s.d != 0);
   346  }
   347  
   348  struct FFS {
   349      void (*xDlSym)(int*, void*, const char* zSymbol);
   350  };
   351  int global_ffs = 0;
   352  void ffs_i1(int* i, void* v, const char* ch)
   353  {
   354      global_ffs++;
   355  }
   356  
   357  void (*ffs_i2(int* i, void* d, const char* zSymbol))(void)
   358  {
   359      return ffs_i1;
   360  }
   361  
   362  void struct_func_func()
   363  {
   364      struct FFS f;
   365      f.xDlSym = ffs_i1;
   366      is_eq(global_ffs, 0);
   367      f.xDlSym(NULL, NULL, NULL);
   368      is_eq(global_ffs, 1);
   369  }
   370  
   371  struct empty_str {
   372  };
   373  typedef struct sqlite3_file sqlite3_file;
   374  struct sqlite3_file {
   375      const struct sqlite3_io_methods* pMethods; /* Methods for an open file */
   376  };
   377  
   378  typedef struct sqlite3_io_methods sqlite3_io_methods;
   379  struct sqlite3_io_methods {
   380      int iVersion;
   381      int (*xClose)(sqlite3_file*);
   382  };
   383  
   384  void struct_after_struct()
   385  {
   386      sqlite3_file sFile;
   387      sqlite3_io_methods io;
   388      sFile.pMethods = &io;
   389      is_not_null(sFile.pMethods);
   390  }
   391  
   392  struct RRR {
   393      struct sColMap { /* Mapping of columns in pFrom to columns in zTo */
   394          int iFrom; /* Index of column in pFrom */
   395          char* zCol; /* Name of column in zTo.  If NULL use PRIMARY KEY */
   396      } aCol[1]; /* One entry for each of nCol columns */
   397  };
   398  
   399  void struct_array()
   400  {
   401      struct RRR rrr;
   402      rrr.aCol[0].iFrom = 10;
   403      is_eq(rrr.aCol[0].iFrom, 10);
   404  }
   405  
   406  typedef struct ss {
   407      char id;
   408  } ss;
   409  int struct_sizeof()
   410  {
   411      ss v;
   412      v.id = 'e';
   413      ss* p = &v;
   414      is_eq(sizeof p->id, 1);
   415      (void)(p);
   416      return -1;
   417  }
   418  
   419  static const struct {
   420      int eType; /* Transformation type code */
   421      int nName; /* Length of th name */
   422      char* zName; /* Name of the transformation */
   423      double rLimit; /* Maximum NNN value for this transform */
   424      double rXform; /* Constant used for this transform */
   425  } aXformType[] = {
   426      { 0, 6, "second", 464269060800.0, 86400000.0 / (24.0 * 60.0 * 60.0) },
   427      { 0, 6, "minute", 7737817680.0, 86400000.0 / (24.0 * 60.0) },
   428      { 0, 4, "hour", 128963628.0, 86400000.0 / 24.0 },
   429      { 0, 3, "day", 5373485.0, 86400000.0 },
   430      { 1, 5, "month", 176546.0, 30.0 * 86400000.0 },
   431      { 2, 4, "year", 14713.0, 365.0 * 86400000.0 },
   432  };
   433  void test_sizeofArray()
   434  {
   435      is_eq((int)(sizeof(aXformType) / (sizeof(aXformType[0]))), 6);
   436  }
   437  
   438  struct StructBase {
   439      union {
   440          struct StructUsed* pStr;
   441          int aaa;
   442      } InsideUnion;
   443  };
   444  struct StructUsed {
   445      int vars;
   446  };
   447  void test_structUsed()
   448  {
   449      struct StructBase sb;
   450      struct StructUsed ss;
   451      sb.InsideUnion.pStr = &ss;
   452      (*sb.InsideUnion.pStr).vars = 10;
   453      is_eq((*sb.InsideUnion.pStr).vars, 10);
   454  }
   455  
   456  struct EmptyName {
   457      union {
   458          long l1;
   459          long l2;
   460      };
   461  };
   462  void test_emptyname()
   463  {
   464      struct EmptyName en;
   465      en.l1 = 10;
   466      is_eq(en.l1, 10);
   467      is_eq(en.l2, 10);
   468  }
   469  
   470  // Link: http://en.cppreference.com/w/c/language/typedef
   471  typedef int A[]; // A is int[]
   472  A a = { 1, 2 }, b = { 3, 4, 5 }; // type of a is int[2], type of b is int[3]
   473  void test_typedef1()
   474  {
   475      is_eq(a[1], 2);
   476      is_eq(b[1], 4);
   477  }
   478  void test_typedef2()
   479  {
   480      typedef float A[];
   481      A a = { 1., 2. }, b = { 3., 4., 5. };
   482      is_eq(a[1], 2.);
   483      is_eq(b[1], 4.);
   484  }
   485  
   486  void test_pointer_member()
   487  {
   488      struct tttt {
   489          int r[10];
   490          int* p;
   491      };
   492      struct tttt t;
   493      t.p = t.r;
   494      for (int i = 0; i < 10; i++)
   495          t.r[i] = i;
   496      is_eq(*t.p, 0);
   497      t.p++;
   498      is_eq(*t.p, 1);
   499      t.p += 2;
   500      is_eq(*t.p, 3);
   501  }
   502  
   503  struct SBA {
   504      int t;
   505      char name[100];
   506  };
   507  
   508  void struct_byte_array()
   509  {
   510      struct SBA sba = { 10, "qwe" };
   511      is_eq(sba.t, 10);
   512      is_streq(sba.name, "qwe");
   513  }
   514  
   515  struct AaA;
   516  typedef struct AaA tAaA;
   517  struct AaA {
   518      int i;
   519  };
   520  void struct_typ2()
   521  {
   522      tAaA a;
   523      a.i = 10;
   524      is_eq(a.i, 10);
   525      struct AaA b = a;
   526      is_eq(b.i, 10);
   527  }
   528  
   529  typedef struct map_node_s map_node_t;
   530  
   531  struct map_node_s {
   532      unsigned hash;
   533      map_node_t* next;
   534  };
   535  
   536  map_node_t* ret()
   537  {
   538      map_node_t mt;
   539      mt.hash = 42;
   540      return &mt;
   541  }
   542  
   543  void test_map_resize()
   544  {
   545      map_node_t mt;
   546      mt.hash = 12;
   547      map_node_t* n = &mt;
   548      is_not_null(n);
   549      is_true(n->hash == 12);
   550      map_node_t* n2 = ret();
   551      is_not_null(n2);
   552      is_true(n2->hash == 42);
   553      n2->hash = 15;
   554      is_true(n2->hash == 15);
   555  }
   556  
   557  typedef float ext_vec;
   558  extern ext_vec Re;
   559  void test_extern_vec()
   560  {
   561      ext_vec e;
   562      Re = 12.0;
   563      e = 5.0;
   564      is_eq(e, 5.0);
   565      is_eq(Re, 12.0);
   566  }
   567  ext_vec Re;
   568  
   569  struct wb {
   570      int i;
   571  };
   572  
   573  int wb_test(struct wb* wb)
   574  {
   575      return wb->i;
   576  }
   577  
   578  void test_same_name()
   579  {
   580      diag("=== same name ===");
   581      {
   582          struct wb wb;
   583          wb.i = 42;
   584          is_eq(wb_test(&wb), 42);
   585      }
   586      {
   587          struct wb tt;
   588          tt.i = 42;
   589          struct wb* wb;
   590          wb = &tt;
   591          is_eq(wb_test(wb), 42);
   592      }
   593      {
   594          struct wb wb[2];
   595          wb[0].i = 42;
   596          wb[1].i = 42;
   597          is_eq(wb_test(&(wb[0])), 42);
   598      }
   599      diag("=================");
   600  }
   601  
   602  typedef int pointx;
   603  typedef struct {
   604      pointx x;
   605      int y;
   606  } Point2;
   607  const Point2 p2[] = { { .y = 4, .x = 5 } };
   608  const Point2* getPoint(int index)
   609  {
   610      return &(p2[index]);
   611  }
   612  typedef unsigned char pcre_uchar;
   613  typedef unsigned char pcre_uint8;
   614  typedef unsigned int pcre_uint32;
   615  typedef struct spu {
   616      pcre_uchar* hvm;
   617  } spu;
   618  
   619  void pointer_arithm_in_struct()
   620  {
   621      pcre_uchar str[] = "abcd";
   622      spu s;
   623      spu* ps = &s;
   624      ps->hvm = &str[1];
   625      is_true(ps->hvm == &str[1]);
   626      ps->hvm += 2;
   627      is_true(ps->hvm == &str[3]);
   628  }
   629  
   630  typedef struct
   631  {
   632      enum { UADD = 0,
   633          UDEL = 1,
   634          UMOV = 2,
   635          VMOV = 3 } typet;
   636      int* head;
   637      int* tail;
   638  } undo;
   639  
   640  void typedef_with_union()
   641  {
   642      diag("typedef with union");
   643      undo u;
   644      (void)(u);
   645      u.typet = UMOV;
   646      is_eq(u.typet, UMOV);
   647      (void)(u.typet);
   648      int y = 53;
   649      u.head = &y;
   650      is_eq(*u.head, y);
   651  
   652      undo u2;
   653      u2.typet = VMOV;
   654      int y2 = 42;
   655      u2.head = &y2;
   656      is_eq(u2.typet, VMOV);
   657      is_eq(*u2.head, y2);
   658  
   659      undo* u3 = &u2;
   660      is_eq((*u3).typet, VMOV);
   661      is_eq(*(*u3).head, y2);
   662  
   663      (*u3).typet = u.typet;
   664      is_eq((*u3).typet, UMOV);
   665  
   666      int bd = UDEL;
   667      (*u3).typet = bd;
   668      is_eq((*u3).typet, UDEL);
   669  }
   670  
   671  typedef union {
   672      void* p;
   673      int b;
   674  } Value;
   675  
   676  #define TValuefields \
   677      Value value;     \
   678      int tt
   679  
   680  typedef struct lua_TValue {
   681      TValuefields;
   682  } TValue;
   683  
   684  void typedef_struct_with_typedef_union()
   685  {
   686      diag("typedef struct with typedef union");
   687      Value v;
   688      v.b = 42;
   689      is_eq(v.b, 42);
   690      TValue tv;
   691      tv.value = v;
   692      tv.tt = 55;
   693      is_eq(tv.value.b, 42);
   694      is_eq(tv.tt, 55);
   695  
   696      TValue* ptv = &tv;
   697      is_eq(ptv->value.b, 42);
   698      is_eq(ptv->tt, 55);
   699  
   700      double d = 45.0;
   701      v.p = &d;
   702      tv.value = v;
   703      is_eq(*((double*)(v.p)), d);
   704      is_eq(*((double*)(ptv->value.p)), d);
   705      is_eq(ptv->tt, 55);
   706  
   707      is_eq(*((double*)((&tv)->value.p)), d);
   708  }
   709  
   710  int add(int a, int b)
   711  {
   712      return a + b;
   713  }
   714  
   715  struct simon {
   716      int (*f)(int, int);
   717      long double g;
   718  };
   719  
   720  void test_struct_with_func()
   721  {
   722      struct simon s1;
   723      s1.f = add;
   724      s1.g = 46.;
   725      is_eq(s1.f(12, 23), 12 + 23);
   726      is_eq(s1.g, 46.);
   727      struct simon* ps = &s1;
   728      is_eq(ps->f(12, 23), 12 + 23);
   729      is_eq(ps->g, 46.);
   730      struct simon as[2];
   731      as[0] = s1;
   732      as[1] = *ps;
   733      is_eq(as[0].f(12, 23), 12 + 23);
   734      is_eq(as[0].g, 46.);
   735      is_eq(as[1].f(12, 23), 12 + 23);
   736      is_eq(as[1].g, 46.);
   737  }
   738  
   739  struct bitstr {
   740      unsigned int a : 1;
   741      unsigned int b : 2;
   742  };
   743  
   744  void test_struct_bit()
   745  {
   746      diag("struct bit");
   747      struct bitstr bs;
   748      bs.a = 1;
   749      bs.b = 2;
   750      is_eq((int)(bs.a), 1);
   751      is_eq((int)(bs.b), 2);
   752  }
   753  
   754  union MyNumber {
   755      int n;
   756      char s[200];
   757  } obj;
   758  
   759  union MyNumber getNumber(char x, int state)
   760  {
   761      union MyNumber tmp;
   762      if (state)
   763          tmp.n = (int)(x + 10 - 'A');
   764      else {
   765          switch (x) {
   766          case 'A':
   767              strcpy(tmp.s, "десять");
   768              break;
   769          case 'B':
   770              strcpy(tmp.s, "одиннадцать");
   771              break;
   772          case 'C':
   773              strcpy(tmp.s, "двенадцать");
   774              break;
   775          case 'D':
   776              strcpy(tmp.s, "тринадцать");
   777              break;
   778          case 'E':
   779              strcpy(tmp.s, "четырнадцать");
   780              break;
   781          case 'F':
   782              strcpy(tmp.s, "пятнадцать");
   783          }
   784      }
   785      return tmp;
   786  }
   787  
   788  void test_union_function()
   789  {
   790      char k;
   791      for (k = 'A'; k <= 'F'; k++) {
   792          union MyNumber m = getNumber(k, 1);
   793          printf("%c - %d\n", k, m.n);
   794      }
   795      for (k = 'A'; k <= 'F'; k++) {
   796          obj = getNumber(k, 0);
   797          printf("%c - %s\n", k, obj.s);
   798      }
   799  }
   800  
   801  int main()
   802  {
   803      plan(127);
   804  
   805      pointer_arithm_in_struct();
   806      test_extern_vec();
   807      test_map_resize();
   808      struct_typ2();
   809      struct_byte_array();
   810      test_pointer_member();
   811      test_typedef1();
   812      test_typedef2();
   813      struct_array();
   814      struct_func_func();
   815      struct_after_struct();
   816      struct_sizeof();
   817      test_sizeofArray();
   818      test_structUsed();
   819      test_emptyname();
   820      test_same_name();
   821  
   822      struct programming variable;
   823      char* s = "Programming in Software Development.";
   824  
   825      variable.constant = 1.23;
   826      variable.pointer = s;
   827  
   828      is_eq(variable.constant, 1.23);
   829      is_streq(variable.pointer, "Programming in Software Development.");
   830  
   831      pass_by_val(variable);
   832      pass_by_ref(&variable);
   833  
   834      struct mainStruct s1;
   835      s1.constant = 42.;
   836      is_eq(s1.constant, 42.);
   837  
   838      secondStruct s2;
   839      s2.constant = 42.;
   840      is_eq(s2.constant, 42.);
   841  
   842      ts_c c;
   843      c.t = 42.;
   844      is_eq(c.t, 42.);
   845  
   846      tt1 t1;
   847      t1.v1 = 42.;
   848      is_eq(t1.v1, 42.)
   849  
   850          tt2 t2;
   851      t2.v1 = 42.;
   852      is_eq(t2.v1, 42.)
   853  
   854          struct ff tf2;
   855      tf2.v2 = t1.v1;
   856      is_eq(tf2.v2, t1.v1);
   857  
   858      struct outer o;
   859      o.i = 12;
   860      o.inner.j = 34;
   861      is_eq(o.i + o.inner.j, 46);
   862  
   863      struct xx x;
   864      x.i = 12;
   865      x.inner.j = 34;
   866      x.inner.deep.k = 56;
   867      is_eq(x.i + x.inner.j + x.inner.deep.k, 102);
   868  
   869      struct u {
   870          int y;
   871      };
   872      struct u yy;
   873      yy.y = 42;
   874      is_eq(yy.y, 42);
   875  
   876      diag("Typedef struct with same name");
   877      {
   878          typedef struct Uq Uq;
   879          struct Uq {
   880              int uq;
   881          };
   882          Uq uu;
   883          uu.uq = 42;
   884          is_eq(uu.uq, 42);
   885      }
   886  
   887      diag("Initialization of struct");
   888      struct Point {
   889          int x;
   890          int y;
   891      };
   892      struct Point p = { .y = 2, .x = 3 };
   893      is_eq(p.x, 3);
   894      is_eq(p.y, 2);
   895  
   896      diag("ImplicitValueInitExpr");
   897      {
   898          typedef struct {
   899              int x2;
   900              int y2;
   901          } coord2;
   902  
   903          typedef struct {
   904              coord2 position2;
   905              int possibleSteps2;
   906          } extCoord2;
   907  
   908          extCoord2 followingSteps[2] = {
   909              { .possibleSteps2 = 1 },
   910              { .possibleSteps2 = 1 },
   911          };
   912          is_eq(followingSteps[0].possibleSteps2, 1);
   913      }
   914      {
   915          struct coord {
   916              int x;
   917              int y;
   918          };
   919  
   920          struct extCoord {
   921              struct coord position;
   922              int possibleSteps;
   923          };
   924  
   925          struct extCoord followingSteps[2] = {
   926              { .possibleSteps = 1 },
   927              { .possibleSteps = 1 },
   928          };
   929          is_eq(followingSteps[0].possibleSteps, 1);
   930      }
   931  
   932      diag("Double typedef type");
   933      {
   934          typedef int int2;
   935          typedef int2 int3;
   936          typedef int3 int4;
   937  
   938          is_eq((int)((int4)((int3)((int2)(42)))), 42);
   939      }
   940      {
   941          typedef size_t size2;
   942          is_eq(((size2)((size_t)(56))), 56.0)
   943      }
   944      {
   945          is_eq((size_t)(43), 43);
   946      }
   947  
   948      diag("Function pointer inside struct");
   949      {
   950          struct F1 {
   951              int x;
   952              int (*f)(int, float);
   953          };
   954          struct F1 f1;
   955          f1.x = 42;
   956          f1.f = summator;
   957          is_eq(f1.x, 42);
   958          is_eq(f1.f(3, 5), 8);
   959      }
   960      {
   961          typedef struct {
   962              int x;
   963              int (*f)(int, float);
   964          } F2;
   965          F2 f2;
   966          f2.x = 42;
   967          f2.f = summator;
   968          is_eq(f2.x, 42);
   969          is_eq(f2.f(3, 5), 8);
   970      }
   971  
   972      diag("typedef function");
   973      {
   974          typedef int ALIAS(int, float);
   975          ALIAS* f = summator;
   976          is_eq(f(3, 5), 8);
   977      }
   978      {
   979          typedef int ALIAS2(int, float);
   980          ALIAS2* f;
   981          f = summator;
   982          is_eq(f(3, 5), 8);
   983      }
   984  
   985      diag("typedef struct C C inside function");
   986      {
   987          typedef struct CCC CCC;
   988          struct CCC {
   989              float ff;
   990          };
   991          CCC c;
   992          c.ff = 3.14;
   993          is_eq(c.ff, 3.14);
   994      }
   995      typedef struct CP CP;
   996      struct CP {
   997          float ff;
   998      };
   999      CP cp;
  1000      cp.ff = 3.14;
  1001      is_eq(cp.ff, 3.14);
  1002  
  1003      diag("struct name from Go keyword");
  1004      {
  1005          struct chan {
  1006              int i;
  1007          };
  1008          struct chan UU;
  1009          UU.i = 5;
  1010          is_eq(UU.i, 5);
  1011      }
  1012      {
  1013          struct defer {
  1014              int i;
  1015          };
  1016          struct defer UU;
  1017          UU.i = 5;
  1018          is_eq(UU.i, 5);
  1019      }
  1020      {
  1021          struct fallthrough {
  1022              int i;
  1023          };
  1024          struct fallthrough UU;
  1025          UU.i = 5;
  1026          is_eq(UU.i, 5);
  1027      }
  1028      {
  1029          struct func {
  1030              int i;
  1031          };
  1032          struct func UU;
  1033          UU.i = 5;
  1034          is_eq(UU.i, 5);
  1035      }
  1036      {
  1037          struct go {
  1038              int i;
  1039          };
  1040          struct go UU;
  1041          UU.i = 5;
  1042          is_eq(UU.i, 5);
  1043      }
  1044      {
  1045          struct import {
  1046              int i;
  1047          };
  1048          struct import UU;
  1049          UU.i = 5;
  1050          is_eq(UU.i, 5);
  1051      }
  1052      {
  1053          struct interface {
  1054              int i;
  1055          };
  1056          struct interface UU;
  1057          UU.i = 5;
  1058          is_eq(UU.i, 5);
  1059      }
  1060      {
  1061          struct map {
  1062              int i;
  1063          };
  1064          struct map UU;
  1065          UU.i = 5;
  1066          is_eq(UU.i, 5);
  1067      }
  1068      {
  1069          struct package {
  1070              int i;
  1071          };
  1072          struct package UU;
  1073          UU.i = 5;
  1074          is_eq(UU.i, 5);
  1075      }
  1076      {
  1077          struct range {
  1078              int i;
  1079          };
  1080          struct range UU;
  1081          UU.i = 5;
  1082          is_eq(UU.i, 5);
  1083      }
  1084      {
  1085          struct select {
  1086              int i;
  1087          };
  1088          struct select UU;
  1089          UU.i = 5;
  1090          is_eq(UU.i, 5);
  1091      }
  1092      {
  1093          struct type {
  1094              int i;
  1095          };
  1096          struct type UU;
  1097          UU.i = 5;
  1098          is_eq(UU.i, 5);
  1099      }
  1100      {
  1101          struct var {
  1102              int i;
  1103          };
  1104          struct var UU;
  1105          UU.i = 5;
  1106          is_eq(UU.i, 5);
  1107      }
  1108      {
  1109          struct _ {
  1110              int i;
  1111          };
  1112          struct _ UU;
  1113          UU.i = 5;
  1114          is_eq(UU.i, 5);
  1115      }
  1116      {
  1117          struct init {
  1118              int i;
  1119          };
  1120          struct init UU;
  1121          UU.i = 5;
  1122          is_eq(UU.i, 5);
  1123      }
  1124      {
  1125          struct len {
  1126              int i;
  1127          };
  1128          struct len UU;
  1129          UU.i = 5;
  1130          is_eq(UU.i, 5);
  1131      }
  1132      {
  1133          struct copy {
  1134              int i;
  1135          };
  1136          struct copy UU;
  1137          UU.i = 5;
  1138          is_eq(UU.i, 5);
  1139      }
  1140      {
  1141          struct fmt {
  1142              int i;
  1143          };
  1144          struct fmt UU;
  1145          UU.i = 5;
  1146          is_eq(UU.i, 5);
  1147      }
  1148      {
  1149          struct cap {
  1150              int i;
  1151          };
  1152          struct cap UU;
  1153          UU.i = 5;
  1154          is_eq(UU.i, 5);
  1155      }
  1156  
  1157      // uncomment after success implementation of struct scope
  1158      // https://github.com/Konstantin8105/c4go/issues/368
  1159      /*
  1160  	diag("Typedef struct name from Go keyword")
  1161  	{ typedef struct {int i;} chan        ;	chan        UU; UU.i = 5; is_eq(UU.i,5);}
  1162  	{ typedef struct {int i;} defer       ;	defer       UU; UU.i = 5; is_eq(UU.i,5);}
  1163  	{ typedef struct {int i;} fallthrough ;	fallthrough UU; UU.i = 5; is_eq(UU.i,5);}
  1164  	{ typedef struct {int i;} func        ;	func        UU; UU.i = 5; is_eq(UU.i,5);}
  1165  	{ typedef struct {int i;} go          ;	go          UU; UU.i = 5; is_eq(UU.i,5);}
  1166  	{ typedef struct {int i;} import      ;	import      UU; UU.i = 5; is_eq(UU.i,5);}
  1167  	{ typedef struct {int i;} interface   ;	interface   UU; UU.i = 5; is_eq(UU.i,5);}
  1168  	{ typedef struct {int i;} map         ;	map         UU; UU.i = 5; is_eq(UU.i,5);}
  1169  	{ typedef struct {int i;} package     ;	package     UU; UU.i = 5; is_eq(UU.i,5);}
  1170  	{ typedef struct {int i;} range       ;	range       UU; UU.i = 5; is_eq(UU.i,5);}
  1171  	{ typedef struct {int i;} select      ;	select      UU; UU.i = 5; is_eq(UU.i,5);}
  1172  	{ typedef struct {int i;} type        ;	type        UU; UU.i = 5; is_eq(UU.i,5);}
  1173  	{ typedef struct {int i;} var         ;	var         UU; UU.i = 5; is_eq(UU.i,5);}
  1174  	{ typedef struct {int i;} _           ;	_           UU; UU.i = 5; is_eq(UU.i,5);}
  1175  	{ typedef struct {int i;} init        ;	init        UU; UU.i = 5; is_eq(UU.i,5);}
  1176  */
  1177  
  1178      struct_with_rec_fuction();
  1179  
  1180      diag("name of struct inside struct");
  1181      {
  1182          typedef struct TI TI;
  1183          struct TI {
  1184              TI *left, *right;
  1185              double varTI;
  1186          };
  1187          TI t1;
  1188          t1.varTI = 4.3;
  1189          TI t2;
  1190          t2.varTI = 4.1;
  1191          TI tt;
  1192          tt.left = &t1;
  1193          (*tt.left).right = &t2;
  1194          tt.right = &t2;
  1195          is_eq((*tt.left).varTI, 4.3);
  1196          is_eq((*(*tt.left).right).varTI, 4.1);
  1197          is_eq((*tt.right).varTI, 4.1);
  1198      }
  1199  
  1200      struct_in_struct_with_star();
  1201      struct_null();
  1202  
  1203      func_in_func_in_struct();
  1204  
  1205      struct_inside_union();
  1206  
  1207      typedef_with_union();
  1208      typedef_struct_with_typedef_union();
  1209      test_struct_with_func();
  1210      test_struct_bit();
  1211      test_union_function();
  1212  
  1213      done_testing();
  1214  }