fork download
  1. /**
  2.   * Tags and typedefs
  3.   */
  4.  
  5. #define ILLEGAL 0
  6.  
  7.  
  8. /*
  9.   * Declare a structure type, with 'tag1' in the
  10.   * tag namespace
  11.   */
  12. struct tag1;
  13.  
  14.  
  15. #if ILLEGAL
  16. /*
  17.   * Cannot use the tag again with a union type,
  18.   * because 'tag1' is already in the tag namespace
  19.   * as a structure tag
  20.   */
  21. union tag1;
  22.  
  23. #endif
  24.  
  25.  
  26. /*
  27.   * Redeclare the same structure type as before
  28.   * and complete the definition of the type
  29.   */
  30. struct tag1 {
  31. int i;
  32. double d;
  33. };
  34.  
  35.  
  36. /*
  37.   * Declare a structure type, a tag, and an object.
  38.   * (Note that 'obj1' is a pointer, not a 'struct tag2')
  39.   */
  40. struct tag2 * obj1;
  41.  
  42.  
  43. #if ILLEGAL
  44. /*
  45.   * Cannot redeclare the tag, for the same reason
  46.   * as before
  47.   */
  48. union tag2 * obj2;
  49.  
  50. #endif
  51.  
  52.  
  53. /* Redeclare the tag2 structure type and complete it */
  54. struct tag2 {
  55. int j;
  56. double e;
  57. };
  58.  
  59.  
  60. /*
  61.   * Declare a union type, its tag, complete the type,
  62.   * declare an object of that type
  63.   */
  64. union tag3 {
  65. short k;
  66. float f;
  67. } obj3;
  68.  
  69.  
  70. /*
  71.   * The tag namespace and the ordinary namespace
  72.   * are different, so there's no conflict, below.
  73.   * There is an 'id4' union type tag, and an 'id4'
  74.   * object
  75.   */
  76. union id4 {
  77. long l;
  78. float g;
  79. } id4;
  80.  
  81.  
  82. #if ILLEGAL
  83. /*
  84.   * But 'int' isn't a tag, so it's in the ordinary
  85.   * namespace and this is a conflict
  86.   */
  87. int int;
  88.  
  89. #endif
  90.  
  91.  
  92. /* Declare a new structure type, with a tag */
  93. struct tag5;
  94.  
  95.  
  96. /*
  97.   * Redeclare that structure type and define an
  98.   * alias for that type
  99.   */
  100. typedef struct tag5 alias5;
  101.  
  102.  
  103. /* These two objects have the same pointer type */
  104. struct tag5 * obj5a;
  105. alias5 * obj5b;
  106.  
  107.  
  108. /* Another structure type, completed */
  109. struct tag6 {
  110. int m;
  111. double h;
  112. };
  113.  
  114.  
  115. /* Another typedef */
  116. typedef struct tag6 alias6;
  117.  
  118.  
  119. /* These objects have the same type */
  120. struct tag6 obj6a;
  121. alias6 obj6b;
  122.  
  123.  
  124. /* Declare a structure type and a type-name alias */
  125. typedef struct tag7 alias7;
  126.  
  127.  
  128. /* These two have the same pointer type */
  129. struct tag7 * obj7a;
  130. alias7 * obj7b;
  131.  
  132.  
  133. /* Complete the structure type */
  134. struct tag7 {
  135. int n;
  136. double d;
  137. };
  138.  
  139.  
  140. /* Now we can declare objects of that complete type */
  141. struct tag7 obj8a;
  142. alias7 obj8b;
  143.  
  144.  
  145. /*
  146.   * Type-name aliases are not in the tag namespace, so
  147.   * there is no conflict, below
  148.   */
  149. struct type9;
  150. typedef struct type9 type9;
  151.  
  152.  
  153. /* Complete the type */
  154. struct type9 {
  155. int o;
  156. double e;
  157. };
  158.  
  159.  
  160. /* These have the same type */
  161. struct type9 obj9a;
  162. type9 obj9b;
  163.  
  164.  
  165. /*
  166.   * Declare a structure type with its tag, complete it,
  167.   * establish a type-name alias
  168.   */
  169. typedef struct type10 {
  170. int p;
  171. float f;
  172. } type10;
  173.  
  174.  
  175. /* These have the same type */
  176. struct type10 obj10a;
  177. type10 obj10b;
  178.  
  179.  
  180. /*
  181.   * Declare a tagless structure type and an object
  182.   * of that type
  183.   */
  184. struct {
  185. int q;
  186. float g;
  187. } obj11;
  188.  
  189.  
  190. /*
  191.   * Declare a tagless structure type and establish a
  192.   * type-name alias for that type
  193.   */
  194. typedef struct {
  195. int r;
  196. short h;
  197. } type12;
  198.  
  199.  
  200. int main(void) { return 0; }
  201.  
Success #stdin #stdout 0s 1784KB
stdin
Standard input is empty
stdout
Standard output is empty