# \[Outreach\] Looking for a simple example of using comptime instead of macros

**URL:** <https://ziggit.dev/t/outreach-looking-for-a-simple-example-of-using-comptime-instead-of-macros/2106>\
**Category:** Brainstorming\
**Tags:** c\
**Created:** [November 2, 2023, 3:42pm UTC](https://ziggit.dev/t/outreach-looking-for-a-simple-example-of-using-comptime-instead-of-macros/2106 "2023-11-02T15:42:21Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![dee0xeed](https://ziggit.dev/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@dee0xeed](https://ziggit.dev/u/dee0xeed)\
**Post date:** [November 7, 2023, 7:39am UTC](https://ziggit.dev/t/outreach-looking-for-a-simple-example-of-using-comptime-instead-of-macros/2106/16 "2023-11-07T07:39:42Z")

</div>

> [@bortzmeyer](#):
>
> Cool example in C, thanks.

With statement expressions (gcc) we can go even farther.  
Look at this fancy macro:

```c
#define fifo_inst(T, name) \
                                                                                    \
T##FifoClass name = { \
    .self = {0}, \
    .put = ({void __fn__ (T *src) {return T##FifoPut(&name.self, src);} __fn__ ;}), \
    .get = ({void __fn__ (T *dst) {return T##FifoGet(&name.self, dst);} __fn__ ;}), \
    .len = ({ u32 __fn__ (void) {return name.self.length;} __fn__ ;}), \
}

```

With this macro (kinda self-made C++ 🙂 ) we can then use fifo (or whatever) like this:

```c
int main(void) {
    inst(fifo, Message, mq1);
    // create an instance (on stack) of fifo named mq1
    ...
    mq1.put(&message[k]);
    ...
    mq1.get(&m);

```

It’s cool, yeah, but it’s a sort of a gimmick, while in Zig generics can be dealt with in more or less standard and clean way.

---

_[View the full topic](https://ziggit.dev/t/outreach-looking-for-a-simple-example-of-using-comptime-instead-of-macros/2106)._
