ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<Snektron> A compromise might be to strip off the VK_ and the enum's type
<Snektron> so that'd by .INSTANCE_CREATE_INFO
<Snektron> Since the enum name is only really there for C reasons
<Snektron> plus it should be rather obvious how to make the change
<Snektron> There is also another thing, which im not quite sure of what to do with it
<Snektron> There are two ways of calling vulkan commands, via static or dynamic dispatch
<Snektron> The dynamic dispatch involves loading functions as function pointers
<Snektron> However, these are unlike OpenGL where those function pointers can be loaded in advance
<Snektron> Instead, there are function pointers for the Instance and each Device
<Snektron> So i'm thinking about whether it makes sense to provide a function to load all those into a struct, or whether its not worth the effort
<Snektron> Where the idea is that developers make their own function pointer tables
return0e has quit [Remote host closed the connection]
adamkowalski has joined #zig
return0e has joined #zig
frmdstryr has joined #zig
mahmudov has quit [Remote host closed the connection]
rageoholic has joined #zig
<rageoholic> Hey guys
<rageoholic> I have a dumb question
<rageoholic> So there's a thing on NVidia and AMD laptops to use dedicated graphics exclusively
<rageoholic> You put _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; in your C file
<rageoholic> What would be the equivalent in Zig
<mikdusan> rageoholic: maybe `export const NvOptimusEnablement: u32 = 0x00000001;` or simply `= 1;`
<mikdusan> andrewrk: does `*align(:3:1) SomeType` mean host integer size is 1 byte, and pointer-child is 3 bits offset into host integer? and what does the missing align num mean?
rageoholic has quit [Ping timeout: 260 seconds]
rageoholic has joined #zig
rageoholic has left #zig [#zig]
lunamn has quit [Ping timeout: 272 seconds]
lunamn has joined #zig
_whitelogger has joined #zig
return0e has quit [Remote host closed the connection]
adamkowalski has quit [Remote host closed the connection]
<fengb> Thoughts on dropping in "Be excellent to each other"?
<fengb> Or would that be bad since it's not a real COC
_whitelogger has joined #zig
mahmudov has joined #zig
qazo has joined #zig
<andrewrk> let's plz not derail the channel by linking to V's CoC
<andrewrk> mikdusan, yes. the alignment value that is missing should be the alignment of the host integer. I think the meaning of when it is missing might be incorrect in stage1 right now
<andrewrk> which might have to do with the incorrect @sizeOf() packed struct which has 3 bytes in it
<andrewrk> here is what it should mean if it is missing: if it is missing then the alignment of the address, which is the address of the host integer, is @alignOf(@IntType(false, 1 * 8)), where 1 is the host integer byte count (the 1 in *align(:3:1))
dddddd has quit [Ping timeout: 268 seconds]
<mikdusan> thanks this helps
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
BaroqueLarouche has quit [Quit: Connection closed for inactivity]
<mikdusan> andrewrk: the first packed-struct at top; am I remotely close with the values?
return0e has joined #zig
qazo has quit [Ping timeout: 240 seconds]
metaleap has joined #zig
<andrewrk> mikdusan, that looks correct to me
<mikdusan> finally I can make some progress :)
ur5us has joined #zig
qazo has joined #zig
_whitelogger has joined #zig
ur5us has quit [Ping timeout: 268 seconds]
___ has joined #zig
___ has quit [Client Quit]
metaleap has quit [Ping timeout: 248 seconds]
waleee-cl has joined #zig
alexpana has joined #zig
alexpana has quit [Read error: Connection reset by peer]
qazo has quit [Ping timeout: 240 seconds]
qazo has joined #zig
<betawaffle> what's the difference between using `var` as an argument type vs. using something like `comptime_int`, besides the fact that the latter can only be an integer?
<betawaffle> and also what's the difference between a comptime_int, and a comptime-known regular int type, like u32? (as an argument type)
<Snektron> comptime int can be any size
<Snektron> A var can be any value
<Snektron> The value can be known at runtime
<Snektron> But the type of the expression has to be known at compile time
<betawaffle> but a `comptime arg: u32` for example has to have a known value at compile time?
<Snektron> Exactly
<Snektron> I do think comptime int stands a bit out
<frmdstryr> Can struct fields be made const so the value can't be changed after it's intialized?
<mq32> frmdstryr, nope, that is not possible
<frmdstryr> Ok thanks
mahmudov has quit [Ping timeout: 268 seconds]
knebulae has quit [Read error: Connection reset by peer]
dddddd has joined #zig
mahmudov has joined #zig
mahmudov has quit [Ping timeout: 240 seconds]
knebulae has joined #zig
<Snektron> Can i import an extern fucntion inside a struct?
<Snektron> `const A = struct { extern fn abc() void; };`
waleee-cl has quit [Quit: Connection closed for inactivity]
<mq32> Snektron, there should be nothing that prevents this
_whitelogger has joined #zig
metaleap has joined #zig
Akuli has joined #zig
dingenskirchen has quit [Read error: Connection reset by peer]
dingenskirchen1 has joined #zig
dingenskirchen1 is now known as dingenskirchen
epmills has joined #zig
<epmills> anyone shed light on declaring an array of anonymous structs?
<epmills> trying to do something like table-driven tests in go: https://github.com/golang/go/wiki/TableDrivenTests
<Snektron> should be possible
<Snektron> The only difference with that example you posted is that you need you name the fields
<Snektron> `const cases = [_]struct{a: u32, b: u32}{.{.a = 10, .b = 20}, .{a = 30, .b = 40}};` should be valid
<Snektron> You could even use an anonymous list of anonymous structs i think
<epmills> Snektron: sorry - being an idiot. was trying to make the struct fields (expected / test value) also anonymous.worked fine like this:
<Snektron> Then you'd write `const cases = .{.{.a = 10, .b = 20}, .{.a = 30, .b = 40}};`
<Snektron> oh
BaroqueLarouche has joined #zig
<Snektron> The above also works but you have to use metafunctions to walk through the fields
<Snektron> `for (std.meta.fields(cases)) |case| testThing(case.a, case.b);`
<epmills> Snektron: interesting - ty!
MrMobius has joined #zig
<MrMobius> hi, does zig have ports for any architectures than x86?
<Snektron> In theory it supports everything that LLVM supports
<Snektron> but in praktise there are some problems with a lot of them
<Snektron> some other architectures are quite well supported though
<MrMobius> Snektron, thanks. looks like there is an msp430 version, which is one I was curious about.
<mq32> how much work is it right now to include a custom OS into zig? is the "custom OS abstraction" already done?
naltun has joined #zig
naltun has quit [Ping timeout: 260 seconds]
decentpenguin has joined #zig
decentpenguin has quit [Client Quit]
decentpenguin has joined #zig
epmills has quit [Remote host closed the connection]
MatrixBridge has joined #zig
MatrixBridge has left #zig ["User left"]
MatrixBridge has joined #zig
MatrixBridge has left #zig ["User left"]
MatrixBridge has joined #zig
MatrixBridge has left #zig ["User left"]
MatrixBridge has joined #zig
MatrixBridge has left #zig ["User left"]
epmills has joined #zig
<andrewrk> mq32, yeah the custom os abstraction is working. a posix-like custom os will fit especially easily
<andrewrk> pixelherodev is taking advantage of this currently, I believe
epmills has quit [Ping timeout: 265 seconds]
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
mahmudov has joined #zig
frmdstryr has quit [Remote host closed the connection]
<fengb> Is there a short summary of all the crazy things LLVM can optimize?
<fengb> Okay not all. Enough to poke around
<fengb> Oh context for the link: Matt Godbolt explaining the history of the compiler explorer
<fengb> Ah neat
epmills has joined #zig
<mikdusan> -instnamer for IR passes :)
epmills has quit [Remote host closed the connection]
BaroqueLarouche has quit [Quit: Connection closed for inactivity]
WendigoJaeger has joined #zig
WendigoJaeger has left #zig [#zig]
<mikdusan> silly question: why is fn return type specified after parens, and not as (optional) final component inside parens? `fn(a:u32, b:u32, u32){return a+b;}`. if this ambiguous?
<andrewrk> for function prototypes (params have no names) it would be ambiguous
<andrewrk> const fnType = fn(u32, u32, u32);
<andrewrk> sorry, it wouldn't be ambigious since the last one would always be the return type. but it does look confusing
epmills has joined #zig
<mikdusan> `const ping := fn{ std.debug.warn("ping!\n",.{}); };`
<mikdusan> ie: deduce if not specified, void
<mikdusan> and if no other args, parens could be omitted entirely
<mikdusan> const run := fn(callback: fn) { callback(); };
<mikdusan> `const add := fn(a:u32, b:u32, Error!u32) { ... };`
<fengb> Not a big fan. fn foo(a: u32, b: u32) is called by foo(a, b). Positions match
epmills has quit [Ping timeout: 268 seconds]
<mikdusan> `const sort := fn(comptime T: type, a: []T, f: fn(T,T,bool)) {...};`
<mikdusan> ah yes andrewrk now I see it
<mikdusan> `const fnType = fn(u32, u32; u32)` <-- ok this is cheating
<mikdusan> `const fnType = fn(;u32)` looks a bit odd but hey...
<andrewrk> what are you trying to solve?
<mikdusan> some interesting proposals. was looking at #4170 and the gist of `.|a,b|` to me seems that it always makes return type inferred and that's why it looks clean. so wondering how we could simply compact all fn stuff
<fengb> What if we had result location based function signatures?
<fengb> Then the types are inferred but not ambiguous
epmills has joined #zig
<mikdusan> afk. got company
adamkowalski has joined #zig
<andrewrk> only 318 errors left in my branch @_@
<andrewrk> 9 files changed, 10412 insertions(+), 8254 deletions(-)
<andrewrk> none of that is automated
traviss has joined #zig
decentpenguin has quit [Quit: decentpenguin]
tobbez has quit [Ping timeout: 246 seconds]
jsmp-me has joined #zig
metaleap has quit [Read error: Connection reset by peer]
metaleap has joined #zig
metaleap has quit [Client Quit]
metaleap has joined #zig
adamkowalski has quit [Remote host closed the connection]
jsmp-me has quit [Ping timeout: 265 seconds]
ur5us has joined #zig
<pixelherodev> Yes, yes I am
<pixelherodev> The custom OS thing that is
jsmp-me has joined #zig
jsmp-me has quit [Ping timeout: 265 seconds]
tobbez has joined #zig
mahmudov has quit [Ping timeout: 240 seconds]
traviss has quit [Remote host closed the connection]
Akuli has quit [Quit: Leaving]
jessermeyer has joined #zig
<jessermeyer> Hey everyone. I'm trying to pass a 0 to a * c_void parameter as part of a C API. How do I do that in Zig?
<jessermeyer> The obvious @intToPtr(*const c_void, 0) amounts to error: pointer type '*const c_void' does not allow address zero
<jessermeyer> Changing 0 to null just changes the error message, about expected sizes.
<jessermeyer> Exploring more, @intToPtr([*c]const c_void, 0) says that C pointers cannot point to opaque types, but that happens in C all the time?
<jessermeyer> Well, looks like translate-c translated the parameter in question to an optional pointer, so just passing null did the trick.
epmills has quit [Remote host closed the connection]
<jessermeyer> What's the defact-o pattern passing Zig arrays to C functions that assume arrays decay to integer (addresses)?
<pixelherodev> Uh... pass the address?
<pixelherodev> jessermeyer, do you mean a slice?
<pixelherodev> Is the type `[*]T` or `[]T`?
<pixelherodev> If the former, pretty sure it can be passed directly
<pixelherodev> If the latter, use `.ptr`
<jessermeyer> error: expected type 'c_ulong', found '*[512:0]c_ulong'
<jessermeyer> Hmm, let me see.
<pixelherodev> That's a pointer to an array of 512 c_ulongs, terminated by zero
<pixelherodev> Try `@ptrToInt`
<pixelherodev> But caution: make sure it's really expecting a pointer
<jessermeyer> Yes, I'm passing a string buffer along.
<pixelherodev> Why is it pointing to c_ulong then?
<pixelherodev> Custom string type?
<pixelherodev> Not judging; I literally am using a relatively stupid custom string type in one of my projects atm
<pixelherodev> s/literally //; it's completely unnecessary
<jessermeyer> Thanks for helping. Sorry it's a bit complicated as it's a maze of type aliases from Windows.h.
<jessermeyer> Trying to simplify it a bit before I respond.
<pixelherodev> Oh god. Working with Windows.h... you have my sympathy.
<jessermeyer> That ... on top of MSDN =)
<jessermeyer> Trying to get FormatMessage working.
<pixelherodev> ... okay so... I can't help there. At least, not off the top of my head the way I could for Linuxisms
<pixelherodev> I haven't used Windows in months, and all of my Windows programming has been over cross-platform abstractions
<jessermeyer> Sure, I was hoping the issue was strictly Zig related.
<jessermeyer> Here's the setup incase you're interested. I wanted a message buffer of 512 bytes, stack allocated, that I pass to FormatMessage.
<jessermeyer> var error_message: [512:0]u8 = undefined;
<jessermeyer> Null-terminated just in case FormatMessage doesn't respect the len argument.
<jessermeyer> FormatMessage's buffer parameter is of type [*c]u8.
<jessermeyer> But if I just pass &error_message, I get error: expected type 'c_ulong', found '*[512:0]c_ushort'
<jessermeyer> Which is ... odd, since that isn't the type of that parameter.. but let me triple check.
<jessermeyer> I may just be an idiot, actually.
<jessermeyer> Yeah, I'm just misusing the function. There was a macro that was doing something funny with parameters that I didn't catch.
<Snektron> They have different names, right?
<jessermeyer> Speaking to me?
<Snektron> jessemeyer, Michaël Larouche 's irc broke
mahmudov has joined #zig
ur5us has quit [Ping timeout: 268 seconds]
epmills has joined #zig
<pixelherodev> jessermeyer, you shouldn't be taking the slice address like that
<pixelherodev> You want `error_message.ptr` to get a `[*]u8`
epmills has quit [Ping timeout: 268 seconds]
<jessermeyer> Huh, should the compiler be yelling at me, cause it's not.
<jessermeyer> But isn't error_message an array?
<pixelherodev> I mean... unless I'm misremembering something
<pixelherodev> Let me just reread them docs real quicl
<pixelherodev> s/quicl/quick
<jessermeyer> I know 'string' handling has changed quite a bit since I last dabbled in Zig, so this stumbling block doesn't surprise me.
jessermeyer has left #zig [#zig]
<pixelherodev> `[512:0]u8`, unless I'm more tired than I thought, is a slice of 512 u8s, zero-terminated
jessermeyer has joined #zig
<pixelherodev> No wait, you're right; it's an array
kynan has joined #zig
<pixelherodev> jessermeyer, you want `&error_message[0]` IIRC
<pixelherodev> The address of the first member
<jessermeyer> So what does &error_message mean?
<pixelherodev> The address of the array itself
<pixelherodev> That is, a `*[512:0]u8`
<pixelherodev> Whereas you want a `[*]u8`
<pixelherodev> (pointer to array of 512 u8s, terminated by zeroes; versus a pointer to an unknown number of u8s)
<pixelherodev> The latter is what C uses
<jessermeyer> I agree that those are technically different at a type level, but isn't the address number of each identical?
<jessermeyer> For whatever reason, zig is cool with taking the address of the array as input.
<pixelherodev> Potentially, but having the type be correct is also a good idea
<pixelherodev> Regardless of whether the generated binary ends up producing the correct result
<pixelherodev> Having all info be correct on the Zig level allows for more correct info to be exposed to, say, the optimizer
<jessermeyer> Yeah I do agree with you there
<pixelherodev> Not necessarily a major concern, but I can imagine the optimizer making an incorrect decision if it thinks the type is something its not
<jessermeyer> Can you think of an instance where the starting byte address would be different?
<jessermeyer> Could alignment cause that to get funky?
<pixelherodev> In C, arrays are just their members - that is, the address of the array == the address of member one
<pixelherodev> I'm not 100% sure if that's true in Zig, give me two seconds
dddddd_ has joined #zig
<pixelherodev> Seems to be, at a quick glance
<jessermeyer> The docs don't mention otherwise, at least.
dddddd has quit [Ping timeout: 272 seconds]
<jessermeyer> But thanks for the helpful advice and assistance =)
<Snektron> Im pretty sure that in practise its the same address, though it doesn't mean the same to the compiler
dddddd_ is now known as dddddd
jessermeyer has quit [Remote host closed the connection]
<pixelherodev> `In theory, theory and practice are the same` <- pretty sure someone used that one yesterday :P
WendigoJaeger has joined #zig
traviss has joined #zig
<traviss> jessermeyer <pass a 0 to a * c_void parameter as part of a C API> maybe you can use an allowzero type? something like `@intToPtr([*c]allowzero c_void, 0)`
<pixelherodev> Nah, null is correct there
<pixelherodev> Source: working on a project that passes null to C code right now :)
<traviss> oh thanks. will use that next time i run into this.
<traviss> much simpler
<pmwhite> What are people's thoughts on language integrated units of measure?
<pixelherodev> Overkill
<pixelherodev> In the standard library, maybe
<pixelherodev> But that doesn't belong in the language itself
<pixelherodev> My two cents
<pmwhite> All the attempts at userland versions in other languages seem to either not have real algebraicness, or aren't ergonomic to use, or aren't "zero-cost"
<metaleap> might be able to whip sth up with comptime as long as "real algebraicness" require "operator-like sigils as func names"
<pmwhite> Which is merely a guess that a library version might not be possible, not a proof that it ought to be included in the language.
<metaleap> s/require/doesnt-require
metaleap has quit [Quit: Leaving]
<pmwhite> In zig at least, you would probably have to forsake using normal math operators.
kynan has left #zig [#zig]
mahmudov has quit [Remote host closed the connection]