modernc.org/ccgo/v3@v3.16.14/lib/testdata/tcc-0.9.27/tests/tests2/17_enum.c (about)

     1  #include <stdio.h>
     2  
     3  enum fred
     4  {
     5     a,
     6     b,
     7     c,
     8     d,
     9     e = 54,
    10     f = 73,
    11     g,
    12     h
    13  };
    14  
    15  /* All following uses of enum efoo should compile
    16     without warning.  While forward enums aren't ISO C,
    17     it's accepted by GCC also in strict mode, and only warned
    18     about with -pedantic.  This happens in the real world.  */
    19  /* Strict ISO C doesn't allow this kind of forward declaration of
    20     enums, but GCC accepts it (and gives only pedantic warning), and
    21     it occurs in the wild.  */
    22  enum efoo;
    23  struct Sforward_use {
    24      int (*fmember) (enum efoo x);
    25  };
    26  
    27  extern enum efoo it_real_fn(void);
    28  enum efoo {
    29    ONE,
    30    TWO,
    31  };
    32  struct S2 {
    33    enum efoo (*f2) (void);
    34  };
    35  void should_compile(struct S2 *s)
    36  {
    37    s->f2 = it_real_fn;
    38  }
    39  
    40  enum efoo it_real_fn(void)
    41  {
    42    return TWO;
    43  }
    44  
    45  static unsigned int deref_uintptr(unsigned int *p)
    46  {
    47    return *p;
    48  }
    49  
    50  enum Epositive {
    51      epos_one, epos_two
    52  };
    53  
    54  int main()
    55  {
    56     enum fred frod;
    57     enum Epositive epos = epos_two;
    58  
    59     printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
    60     /* printf("%d\n", frod); */
    61     frod = 12;
    62     printf("%d\n", frod);
    63     frod = e;
    64     printf("%d\n", frod);
    65  
    66     /* Following should compile without warning.  */
    67     printf ("enum to int: %u\n", deref_uintptr(&epos));
    68  
    69     return 0;
    70  }
    71  
    72  /* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/