ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
Zaab1t has quit [Quit: bye bye friends]
voldyman has joined #zig
lqd has quit [Quit: Connection closed for inactivity]
_whitelogger has joined #zig
kristate has joined #zig
kristate has quit [Ping timeout: 250 seconds]
_whitelogger has joined #zig
darithorn has quit [Read error: Connection reset by peer]
Ichorio has joined #zig
MajorLag has quit [Ping timeout: 264 seconds]
kristate has joined #zig
Ichorio has quit [Ping timeout: 240 seconds]
Ichorio has joined #zig
forgot-password has joined #zig
very-mediocre has joined #zig
zange has quit [Ping timeout: 250 seconds]
Ichorio has quit [Read error: Connection reset by peer]
forgot-password has quit [Ping timeout: 245 seconds]
Ichorio has joined #zig
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 250 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 246 seconds]
forgot-password has joined #zig
forgot-password has quit [Ping timeout: 250 seconds]
forgot-password has joined #zig
<forgot-password> Is it possible to have @compileLog not abort compilation? Or is std.debug.warn intended to take that place once https://github.com/ziglang/zig/313 is fixed?
Zaab1t has joined #zig
wootehfoot has joined #zig
darithorn has joined #zig
_whitelogger has joined #zig
kristate has quit [Remote host closed the connection]
very-mediocre has quit [Ping timeout: 256 seconds]
forgot-password has quit [Changing host]
forgot-password has joined #zig
forgot-password has quit [Quit: leaving]
forgot-password has joined #zig
kristate has joined #zig
kristate has quit [Remote host closed the connection]
MajorLag has joined #zig
so has quit [Ping timeout: 246 seconds]
so has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
<forgot-password> exit
<forgot-password> Oops, sorry :)
forgot-password has quit [Quit: leaving]
hooo has quit [Quit: Connection closed for inactivity]
vegecode has joined #zig
<vegecode> hey all, I have a struct and I want to use std.mem.compare to compare two of them. How can I turn it into a slice? I tried (&my_struct)[0..] and a few other tries.
steveno has joined #zig
<MajorLag> std.mem.asBytes(&my_struct) will return a pointer to a byte array
<vegecode> Thanks
<vegecode> Talk about unwieldy though
<MajorLag> it's explicit. comparing structs this way isn't the best anyway, because padding bytes can differ between otherwise identical structs. That's why there's std.mem.eql
<vegecode> That should be in the docs maybe. How the heck could I have found that on my own in a reasonable amount of time?
<MajorLag> the std library isn't documented yet, in part because it's big and changes frequently. It's on the todo list.
<MajorLag> sorry, I meant std.meta.eql, not mem.eql
<MajorLag> completely different
<MajorLag> meta.eql will use typeInfo to compare every field, so the padding bytesare ignored.
<MajorLag> that call would just be `std.meta.eql(my_struct_a, my_struct_b);`
<vegecode> Thanks!
<redj> MajorLag: ignore this if you're busy but I'm curious... how would that happen? why would padding bytes differ between "otherwise identical structs" and is that structs with the same fields of same data type in same order? sadly I'm not familiar with all this padding memory stuff... :P
<vegecode> I would think that a single compilation unit would have all structs of the same type have the same padding. Is this not true?
<MajorLag> They have the same number of bytes for padding, but because those bytes don't belong to a field they're left undefined, so they could be whatever was in that memory before you created the struct. If you then compare the structs byte-by-byte, you're comparing the contiguous memory the structs occupy, which includes the undefined bytes.
<MajorLag> does that make sense?
<vegecode> It does, I'm surprised the compiler doesn't zero initialize those unnamed fields. I keep getting stuck in a C way of thinking. I keep making the "&&" comparison mistake.
<MajorLag> zero initialization has a cost.
<redj> ah, undefined paddyng bytes, makes sense
<MajorLag> and also is probably optimized out all the time whether you want it to be or not
<redj> I thought you meant the padding wasn't in the same location or something
<MajorLag> Well actually,a small modification to std.meta.eql would let you compare structs that have the same field names, but in different locations.
<redj> yay for optimility! ;)
<redj> optimality* or being optimal
<MajorLag> Right now meta.eql enforces that you pass it the same type for each parameter, but it doesn't have to.
<redj> I guess optimiality is a thing in linguistics... I wonder if it can apply to programming languages... perhaps not.
<MajorLag> In fact, I'm toying with a similar idea in my rewrite of my image libraries. you can pass the RGB pixel format you want as a struct (packed struct{r: u5, g: u6, b: u5}, for instance.) and the code can automatically convert the source data before dumping it into your buffer.
<vegecode> It's guaranteed by the c standard for non initialized fields. If it is optimized out then the compiler is not standards compliant I believe.
<vegecode> But you're right
<vegecode> why not just use the abilities of the more advanced compiler?
<vegecode> Thanks again for taking the time to respond.
<MajorLag> I don't know precisely what zig's defined behavior for structpadding byte initialization is. It probably does set it to 0 in at least debug and safe modes.
darithorn has quit [Quit: Leaving]
<vegecode> I am also testing some code for putting a terminal into raw mode so that I can do a readline type of clone. If a test fails, the defer statement I have that is supposed to restore the terminal to canonical mode doesn't run. Can I override the panic function for test mode only?
steveno has quit [Ping timeout: 252 seconds]
<MajorLag> I think what you'd do is override the panic and check the current build mode using something like `if(builtin.is_test) myPanic() else defaultPanic()`
<MajorLag> but someone who actually has overridden panic before would be a better source of information on that
vegecode has quit [Ping timeout: 240 seconds]
noonien has joined #zig
noonien is now known as nuunien
nuunien is now known as noonien
Zaab1t has quit [Quit: bye bye friends]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
Thalheim has joined #zig
steveno has joined #zig