~sircmpwn/hare-users

2 2

How to replace *void for default value initialization

Details
Message ID
<878rd1w2ew.fsf@greenfork.me>
DKIM signature
pass
Download raw message
Hi,

I'm reviving hare-sqlite

https://git.sr.ht/~blainsmith/hare-sqlite

I get errors from the yesterday Hare build, how do I correctly convert
this struct

        export type handle = struct {
                sqlite: *void,
        };

That is used as follows

        let h = alloc(handle { ... });
        wrapvoid(_open(_filename, &h.sqlite))?;

Currently the errors is

        Field 'sqlite' is uninitialized

        18 |		let h = alloc(handle { ... });

Regards,
Dmitry.
Details
Message ID
<CT37YYISY4UK.1MHUO2NW8DQ2K@flagship>
In-Reply-To
<878rd1w2ew.fsf@greenfork.me> (view parent)
DKIM signature
pass
Download raw message
hey,

pointers don't have a default value to be used by `...`,
so you'd need to get the db handle before allocating the struct:

	let db: nullable *void = null;
	wrapvoid(_open(_filename, &db))?;
	let h = alloc(handle {
		sqlite = db as *void,
	});

though i'm not sure why `handle` isn't simply `*void` directly,
maybe the struct was meant to be extended in the future but otherwise
it should probably just be dropped? i.e.

	let db: nullable *void = null;
	wrapvoid(_open(_filename, &db))?;
	return db as *void;
Details
Message ID
<87sfb7vg1s.fsf@greenfork.me>
In-Reply-To
<CT37YYISY4UK.1MHUO2NW8DQ2K@flagship> (view parent)
DKIM signature
pass
Download raw message
"Jonas Fentker" <jonas@fentker.eu> writes:

> 	let db: nullable *void = null;
> 	wrapvoid(_open(_filename, &db))?;
> 	return db as *void;

That works, thanks!

I guess the struct was there to make it a "distinct" type so that you
can't pass another *void to the same parameter.
Reply to thread Export thread (mbox)