ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
knebulae has joined #zig
<emekoi> does the example hello_libc work currently?
<emekoi> because if you export main in your root file and link libc doesn't the main in bootstrap also get exported?
kristate has joined #zig
marmotini has joined #zig
marmotini has quit [Ping timeout: 246 seconds]
emekoi has quit [Remote host closed the connection]
unique_id has joined #zig
<unique_id> I'm going to stop using "use @import". For some reason I was stuck in the ways of C/C++ but I now see how much better zig's recommended way of doing things is. Also, though I don't think I'm using many globals, it kinda makes them less terrible because it's more obvious when code is using globals (a global from another file isn't referred to in the same ways as local variables).
hooo has quit [Quit: Connection closed for inactivity]
kristate has quit [Remote host closed the connection]
unique_id has left #zig ["Konversation terminated!"]
kristate has joined #zig
kristate has quit [Ping timeout: 240 seconds]
<testuser678> What allocator should I be using in "production" code? Do people lean on the debug.global_allocator?
kristate has joined #zig
kristate has quit [Ping timeout: 258 seconds]
<daurnimator> testuser678: depends..... are you writing a library? or an application? do you want to use the libc allocator? are you linking against libc?
<MajorLag> debug.global_allocator is a fixed-size buffer that never frees. Absolutely should not be used in production. Generally speaking, use DirectAllocator and layer an appropriate allocator for each problem on top of it.
<MajorLag> Well, ok, global_allocator is just a FixedBufferAllocator, so as long as you never need more than the fixed buffer size (10MiB IIRC) you'll be ok, but you should probably just use your own defined fixed buffer and FixedBufferAllocator.
<daurnimator> MajorLag: it's not a terrible choice for short lived scripts.
kristate has joined #zig
<daurnimator> (or misc small purpose command line tools)
<MajorLag> I suppose not, but you can accomplish the same thing using your own FBA and it won't have the smell of depending on something in the debug namespace.
<andrewrk> I think std.debug.global_allocator is too easy to abuse. certainly libraries should not use it, not even in library tests. because you don't know how much memory other libraries will use
<andrewrk> it's handy for writing unit tests for applications, but then you have to have the discipline to rewrite your passing unit test with a fixed buffer allocator
<andrewrk> I don't have plans to yank it from standard library, but I would consider it deprecated for internal use in the standard library
marmotini has joined #zig
marmotini has quit [Ping timeout: 258 seconds]
marmotini has joined #zig
daurnimator has quit [Ping timeout: 268 seconds]
daurnimator has joined #zig
fsateler has quit [Read error: Connection reset by peer]
fsateler has joined #zig
hooo has joined #zig
Zaab1t has joined #zig
fsateler_ has joined #zig
fsateler has quit [Read error: Connection reset by peer]
dpk has quit [Ping timeout: 260 seconds]
dpk has joined #zig
Zaab1t has quit [Ping timeout: 245 seconds]
_whitelogger has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
kristate has quit [Ping timeout: 268 seconds]
Zaab1t has joined #zig
kristate has joined #zig
kristate has quit [Ping timeout: 244 seconds]
forgot-password has joined #zig
steveno has joined #zig
kristate has joined #zig
kristate has quit [Ping timeout: 250 seconds]
marmotini has quit [Ping timeout: 258 seconds]
Zaab1t has quit [Ping timeout: 250 seconds]
kristate has joined #zig
<forgot-password> Why is it, that when I access the field of a struct via a variable I need to get a pointer to that field? Do the values get copied otherwise?
<andrewrk> I'm not sure what you're talking about
<andrewrk> do you have a code example?
zezic has joined #zig
<forgot-password> Say I have a value of type A, which has a field of type B: var a = A { .field = B { .value = 42 } };
<forgot-password> Then I want to modify a.field.value like this: var field = a.field; field.value = 0;
<forgot-password> But that didn't work, I had to do it like this: var field = &a.field; field.value = 0;
<forgot-password> Does a.field get copied into my stack in the first example, instead of having a reference to a.field?
kristate has quit [Ping timeout: 258 seconds]
<forgot-password> Well, I guess that makes sense, since I then have a pointer to a B, right?
<andrewrk> that's right. when you use `var` you are declaring a memory location. so the field `field` was copied into the variable `field`'s memory. Then your next statement modifies the variable `field`s memory
<andrewrk> when you use a variable that is a pointer, you're still declaring a memory location. but then the memory location you are declaring is the pointer bytes, not the actual data bytes
<andrewrk> your pointer variable can probably be const
<forgot-password> If I were writing C I would have to set the value of that pointer via `field->value = 42;`, correct?
<forgot-password> Not the value of the pointer, I meant the value of the struct the pointer is referencing
<forgot-password> the value of the field*, to be 100% correct
steveno has quit [Ping timeout: 264 seconds]
zezic has quit [Quit: zezic]
zezic has joined #zig
zezic has quit [Client Quit]
zezic has joined #zig
<andrewrk> forgot-password, no, you'd have the same issue in C
<andrewrk> you'd still have to use a pointer
<andrewrk> but then yes, to access fields from pointers in C you have to use ->
<forgot-password> No wait, I was already assuming to have a pointer
<forgot-password> Alright, thanks. :)
<andrewrk> sorry, I misunderstood
<forgot-password> No worries, I didn't make it easy to understand :p
forloveofcats[m] has joined #zig
Zaab1t has joined #zig
btbytes has joined #zig
halosghost has joined #zig
forgot-password has quit [Quit: leaving]
Ichorio has joined #zig
<forloveofcats[m]> Is there some way to convert instances of builtin types to strings? I am trying to write a usize to the console and I cannot just cast to u8 as that would output an ASCII character instead of the value "as" a string.
<andrewrk> forloveofcats[m], have you seen the family of functions in std.fmt?
<andrewrk> what OS are you targeting?
<forloveofcats[m]> Oooooh that looks nice
<forloveofcats[m]> I am currently on Windows but usually use GNU/Linux
<andrewrk> std.debug.warn("here is my usize: {}\n", x);
<forloveofcats[m]> Ok apparently I'm just dumb. I saw that trick for warn but I thought that warn only worked with compile-time values as I had had errors with it before, turns out I needed to remove the `try`...
steveno has joined #zig
<forloveofcats[m]> Is there any documentation for the standard library?
<forloveofcats[m]> if so where may I find it?
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
steveno has quit [Remote host closed the connection]
steveno has joined #zig
very-mediocre has joined #zig
belgin has joined #zig
Hejsil has joined #zig
<Hejsil> andrewrk, fun-with-zig would probably be a good test repo for copy elision
<andrewrk> Hejsil, ah yes of course. I'll be sure to look at that one
<MajorLag> Wasn't someone working on draft std docs? Or was it more of a doc generator?
marmotini_ has joined #zig
meheleventyone has joined #zig
<andrewrk> I believe hryx started the effort
<andrewrk> it's a big project though
very-mediocre has quit [Ping timeout: 256 seconds]
wootehfoot has joined #zig
belgin has quit [Remote host closed the connection]
<andrewrk> hmm, I just noticed that the logic for the return type of functions in @typeInfo is very questionable. I missed it in code review
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
forgot-password has joined #zig
steveno has quit [Ping timeout: 260 seconds]
forgot-password has quit [Read error: Connection reset by peer]
marmotini_ has quit [Ping timeout: 244 seconds]
forgot-password has joined #zig
return0e has quit [Remote host closed the connection]
<testuser678> I'm writing some code that is decoding binary structures from a byte slice - what's the safest way to reinterpret the bytes? In C I'd check that the number of bytes is sizeof(MyStruct) and cast a pointer to it - is there an idiomatic way to do that in Zig?
return0e has joined #zig
btbytes has quit [Quit: Textual IRC Client: www.textualapp.com]
<Hejsil> testuser678, if you have a slice of bytes, you can do: if (bytes.len != @sizeOf(T)) return; const t = @bytesToSlice(T, bytes);
<Hejsil> @bytesToSlice(T, bytes)[0]*
return0e has quit [Ping timeout: 245 seconds]
return0e has joined #zig
<MajorLag> andrewrk: I'm not surprised, @typeInfo is really useful but it strikes me as needing quite a bit of cleanup.
<MajorLag> not to mention we still have to figure out the situation with generic parameters and return types...
Hejsil has quit [Ping timeout: 256 seconds]
Zaab1t has quit [Quit: bye bye friends]
zez1c has joined #zig
zezic has quit [Ping timeout: 246 seconds]
zez1c is now known as zezic
halosghost has quit [Quit: WeeChat 2.3]
<andrewrk> 497 / 521 behavior tests passing in copy elision branch
zezic has quit [Remote host closed the connection]
forgot-password has quit [Quit: leaving]
wootehfoot has quit [Read error: Connection reset by peer]
Ichorio has quit [Ping timeout: 244 seconds]
Ichorio has joined #zig
n3t has joined #zig
<n3t> Hi \o