# Using VOID as a const

**URL:** <https://ziggit.dev/t/using-void-as-a-const/18440>\
**Category:** Brainstorming\
**Created:** [November 12, 2026, 2:25pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440 "2026-11-12T14:25:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 12, 2026, 2:25pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440/1 "2026-11-12T14:25:51Z")

</div>

Sometimes I use (comptime optional) void arguments in a function.

For example:

```zig
fn get_image(
    comptime T: ImageType, 
    info: if (T == .animation) *const ImageInfo else void) *const Image {
    // if animation use info otherwise ignore.
}

```

and I call it like this for a non-animation:

```zig
const img = get_image(.default, VOID);
const img = get_image(.default, {}); // instead of this

```

to be able to grep search for these kind of callsites I was thinking about a global const:

```zig
pub const VOID: void = {};

```

because searching for `{}` in an entire project is quite useless 🙂

Any thoughts on this VOID const idea?  
Any thoughts on alternatives?

---

<div class="post-metadata">

**Author:** ![the25thwam](https://ziggit.dev/user_avatar/ziggit.dev/the25thwam/32/10580_2.png) [@the25thwam](https://ziggit.dev/u/the25thwam)\
**Post date:** [November 12, 2026, 2:50pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440/2 "2026-11-12T14:50:22Z")

</div>

I would probably just use a union for this:

```zig
const ImageInfo = union(enum) {
    default,
    animation: *const AnimationInfo,
    // other options...

    const AnimationInfo = struct {
        // ...
    };
};

fn get_image(info: ImageInfo) *const Image {
    // ...
}

```

which you would use like:

```zig
const img = get_image(.default);
const img = get_image(.{ .animation = &animation_info });

```

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [November 12, 2026, 7:26pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440/3 "2026-11-12T19:26:07Z")

</div>

> [@the25thwam](#):
>
> I would probably just use a union for this:

This has runtime costs, while the void approach doesn’t.

---

<div class="post-metadata">

**Author:** ![IntegratedQuantum](https://ziggit.dev/user_avatar/ziggit.dev/integratedquantum/32/782_2.png) [@IntegratedQuantum](https://ziggit.dev/u/IntegratedQuantum)\
**Post date:** [November 12, 2026, 8:15pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440/4 "2026-11-12T20:15:30Z")

</div>

A global constant has the issue, that you need to remember to use it and have the friction of importing it.  
You could instead use an enum e.g. `enum {void}`. Note that enums with one element are also 0-bit types, just like `void`. This would make the callsite take `.void` which is easier to grep:

```zig
const img = get_image(.default, .void);

```

Another advantage of enums over constants is that you could get autocomplete for it (not sure if it works yet, ZLS is known to have some limitations with comptime code, but it will work eventually).

Also couldn’t you just grep for `, {}` or `, {})`? That could narrow it down sufficiently.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [November 12, 2026, 8:21pm UTC](https://ziggit.dev/t/using-void-as-a-const/18440/5 "2026-11-12T20:21:34Z")

</div>

Excellent idea! I’ll check that one out.
