#Help With Tuples

1 messages · Page 1 of 1 (latest)

wise jungle
#

Trying to return a tuple of types u32 and ?*anyopaque, how do I change this declaration to include anyopaque pointers?

sweet jacinth
#

var result: struct { u32, ?*anyopaque } = .{ 0, null } not giving it a type makes it a bit less useful

sweet jacinth
#

iirc itll be a struct { comptime_int, @TypeOf(null) } as you had it, theres no default int type and it cant infer what kind of “nullable” you want

wise jungle
#

Can you name the individual values? I know that's basically a struct at that point but I'm trying to just do multiple return without needing to declare a struct

sweet jacinth
#

so youd have to declare a struct. or just make result the two items seperately and do return .{ .a = result_a, b = result_b }

#

or to be silly you could inspect the return type of the current function lol

wise jungle
#

Wait what. Wdym structural equality. Also I do just want to return a tuple because I don't want to use a struct

#

Also that's kind of ironic that structs don't have structural equality

sweet jacinth
#

structural equality pretty much means that two types that have the same structure are considered the same type. like struct { T } == struct { T } works but struct { name: T } == struct { name: T } doesnt.

sweet jacinth
#

although extern structs also have a defined layout so maybe its more about explicit coercion between genuinely “different” types

#

oh if your question was if you could name specifically tuple fields, no. they’re always “unnamed” (though each field does have a name, its just the index you access it at, so you can do tuple_val.@"0" if you wanted to)

wise jungle
sweet jacinth
#

extern on a struct means “conform this struct to the C ABI”. export is kinda the same thing for functions, i dont know the terms but its for making a library that C can call into

#

well, C and anything that can call into C. like cross-language stuff

snow quartz