anonymously initializing pointers in self-referential data-structures?

I have a recursive data-structure (a simple linked list for purposes of this example) and wanted to statically define a linked-list. The following works fine:

#include <stdio.h>
typedef struct mytype_tag {
    struct mytype_tag* next;
    char* data;
} mytype;

mytype a = {
    .next = NULL,
    .data = "a",
};
mytype b = {
    .next = &a,
    .data = "b",
};

int
main() {
    mytype* s = &b;
    int i = 0;
    while (s) {
        printf("%d: %s\n", i++, s->data);
        s = s->next;
    };
}

However, I have to explicitly define/declare a and then have b take &a.

Is there a way to do this with anonymous/unnamed intermediary structures, thinking an imaginary syntax something like

mytype b = {
    .next = &((mytype)={
        .next = NULL,
        .data = "a",
        }),
    .data = "b",
};

so I can build up the linked-list without naming each intermediary instance?

reddit.com
u/gumnos — 13 hours ago

anonymously initializing static pointers in self-referential data-structures?

I have a recursive data-structure (a simple linked list for purposes of this example) and wanted to statically define a linked-list. The following works fine:

#include <stdio.h>
typedef struct mytype_tag {
    struct mytype_tag* next;
    char* data;
} mytype;

mytype a = {
    .next = NULL,
    .data = "a",
};
mytype b = {
    .next = &a,
    .data = "b",
};

int
main() {
    mytype* s = &b;
    int i = 0;
    while (s) {
        printf("%d: %s\n", i++, s->data);
        s = s->next;
    };
}

However, I have to explicitly define/declare a and then have b take &a.

Is there a way to do this with anonymous/unnamed intermediary structures, thinking an imaginary syntax something like

mytype b = {
    .next = &((mytype)={
        .next = NULL,
        .data = "a",
        }),
    .data = "b",
};

so I can build up the linked-list without naming each intermediary instance?

reddit.com
u/gumnos — 14 hours ago

actual algorithm for finding transactions with xact?

I have a shell-function that uses ledger xact to identify a past-transaction matching a term and then update it with a new amount, so I can do things like

$ pay kroger 31.41

and it finds the most recent Kroger transaction and appends it to my transaction-log with the updated $31.41

It usually works fine. But for some reason, my transactions with Nothing Bundt Cakes consistently find a weird transaction. Today I issued

$ pay bundt 5.99

There were definite exact-match transactions for "bundt" that it should have found, and the only exact-match for "bundt" in my entire transaction-log is the one I wanted. Yet for some reason ledger instead identified some Lowe's transaction for a toilet-flapper and light-bulbs.

How does xact make its choice of which transaction gets matched?

reddit.com
u/gumnos — 10 days ago

Looking for a CLI roguelike for elementary age kids

My elementary-school aged daughter has been having fun learning the ropes of some of the classic bsdgames collection on an old OpenBSD laptop I had laying around. I happened to mention nethack and rogue in passing and she had an interest in trying them. But I'm concerned they're a lot more involved/complex than a quick dungeon-romp, and that she'd get overwhelmed or annoyed and disregard roguelikes completely.

Are there any "Nethack Junior" or "Rogue Junior" type games for the terminal that folks would recommend I try? Bonus points if they run on OpenBSD (most terminal applications would), but it's not a deal-killer.

Thanks!

reddit.com
u/gumnos — 2 months ago