@@ -212,6 +212,21 @@ Pack Aspect
212
212
pragma Pack (Ar);
213
213
-- Rec'Size is 36, Ar'Size is 1000
214
214
215
+ -------------------------------
216
+ Enum Representation Clauses
217
+ -------------------------------
218
+
219
+ * Can specify representation for each value
220
+ * Representation must have increasing number
221
+
222
+ .. code :: Ada
223
+
224
+ type E is (A, B, C);
225
+ for E use (A => 2, B => 4, C => 8);
226
+
227
+ * Can use :ada: `E'Enum_Rep (A) = 2 `
228
+ * Can use :ada: `E'Enum_Val (2) = A `
229
+
215
230
-------------------------------
216
231
Record Representation Clauses
217
232
-------------------------------
@@ -251,6 +266,30 @@ Record Representation Clauses
251
266
D at 5 range 0 .. 2;
252
267
end record;
253
268
269
+ ------------------
270
+ Unchecked Unions
271
+ ------------------
272
+
273
+ * Allows replicating C's :c: `union ` with **discriminated ** records
274
+ * Discriminant is **not stored **
275
+ * No discriminant check
276
+ * Object must be **mutable **
277
+
278
+ .. code :: Ada
279
+
280
+ type R (Is_Float : Boolean := False) is record
281
+ case Is_Float is
282
+ when True =>
283
+ F : Float;
284
+ when False =>
285
+ I : Integer;
286
+ end case;
287
+ end record
288
+ with Unchecked_Union;
289
+
290
+ O : R := (Is_Float => False, I => 1);
291
+ F : Float := R.F; -- no check!
292
+
254
293
------------------------------
255
294
Array Representation Clauses
256
295
------------------------------
0 commit comments