# Using void in nested unions

**URL:** <https://forum.opencyphal.org/t/using-void-in-nested-unions/268>\
**Category:** Applications & Usage\
**Created:** [November 22, 2018, 7:36am UTC](https://forum.opencyphal.org/t/using-void-in-nested-unions/268 "2018-11-22T07:36:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [November 22, 2018, 7:36am UTC](https://forum.opencyphal.org/t/using-void-in-nested-unions/268/1 "2018-11-22T07:36:04Z")

</div>

Hi! I have the following situation:

```auto
# Service type
test.TypeA
   uint8 cmd_code

   ---

   uint8 resp_code
   # Proper to add void4 here?
   TypeB Payload

# Nested type
test.TypeB
  # Adding void here is not allowed, compile error, hence the union
  @union
  uint8 x
  TypeC foo
  TypeC bar
  uint8 y

# Nested type
test.TypeC
   @union
   uint8 xx
   float32 yy
   int32 zz

```

TypeC will create a 2bit tag and needs outer void6 to be aligned.

Question1:  
How do I align the data properly, hence I cannot add void into a type with union?

Question2:  
In test.TypeB there are two TypeC included. They will totally add up needing void12, is it enough to add void4 (modulo8) in test.TypeA for proper alignment?

Kind regards

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [November 23, 2018, 10:58am UTC](https://forum.opencyphal.org/t/using-void-in-nested-unions/268/2 "2018-11-23T10:58:02Z")

</div>

> [@deekay](#):
>
> How do I align the data properly, hence I cannot add void into a type with union?

Either put voids directly before your unions as you did above or create wrapper types, where the wrapper type would contain simply your union prefixed with a void.

> [@deekay](#):
>
> In test.TypeB there are two TypeC included. They will totally add up needing void12, is it enough to add void4 (modulo8) in test.TypeA for proper alignment?

Use wrapper types here. This is the only way to implement robust alignment here.

That said, alignment is not required. If your data structures are small and simple, you can simply leave fields unaligned, it’s perfectly acceptable.

---

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [November 23, 2018, 11:24am UTC](https://forum.opencyphal.org/t/using-void-in-nested-unions/268/3 "2018-11-23T11:24:19Z")

</div>

Ok! Thank for the reply!

Kind Regards
