Skip to content

Commit b243584

Browse files
committed
Merge branch '110-low-level-improvements' into 'master'
Resolve "Low level improvements" Closes #110 See merge request feng/training/material!209
2 parents 5c799e6 + 5f8eba9 commit b243584

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

courses/fundamentals_of_ada/adv_280_low_level_programming.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ Pack Aspect
212212
pragma Pack (Ar);
213213
-- Rec'Size is 36, Ar'Size is 1000
214214
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+
215230
-------------------------------
216231
Record Representation Clauses
217232
-------------------------------
@@ -251,6 +266,30 @@ Record Representation Clauses
251266
D at 5 range 0 .. 2;
252267
end record;
253268
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+
254293
------------------------------
255294
Array Representation Clauses
256295
------------------------------

0 commit comments

Comments
 (0)