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/
<daurnimator> zags: llvm optional. not removed
<g-w1> the latter, but the self-hosted backends will have the low hanging optimisations
<daurnimator> zags: which is to say: for a release build, you'll want to use LLVM with all its optimizations; but for debug builds and while working on the code, use the self-hosted backend
<zags> yeah that's what I meant by switching to llvm for release builds
<zags> cool beans
<zags> there are important relwithdebinfo cases
<zags> is optimized debug builds something that is/will be supported?
kbd has joined #zig
<daurnimator> zags: even full release builds have proper debug info
<daurnimator> (though things might be optimized out etc)
<zags> oh ok, very nice
<zags> yeah, we need to get proper backtraces from customers while having them run at full speed
kbd has quit [Client Quit]
<g-w1> release-small and fast optimises it out?
<daurnimator> g-w1: huh?
<justin_smith> what I found counterintuitive is that "--release-debug" isn't the flag for dev builds - with no release flag you get unoptimized and debuggable, --release-debug is when you want optimizations but also debug info
<justin_smith> or something like that
<daurnimator> there is no --release-debug.... zig has Debug, ReleaseSmall, ReleaseSafe, ReleaseFast
<justin_smith> sorry, I misremembered the flag
<daurnimator> all of them come with debug info
<justin_smith> daurnimator: right, but when I used --release-safe that was more optimized, and less friendly for debugging, than what I got when I used no --release-foo flag (the default, which I guess is how you get debug)
<daurnimator> yes. release-safe is "go as fast as you can; but most undefined behaviour will be safely caught"
<daurnimator> release-fast is "go as fast as you can; I understand that undefined behaviour may lead to nasal demons"
ur5us_ has quit [Ping timeout: 264 seconds]
zags has quit [Quit: leaving]
dddddd has quit [Ping timeout: 256 seconds]
kbd has joined #zig
Xatenev has joined #zig
ur5us_ has joined #zig
dddddd has joined #zig
cole-h has quit [Ping timeout: 246 seconds]
dddddd has quit [Ping timeout: 256 seconds]
nvmd has joined #zig
dddddd has joined #zig
leon-p has quit [Remote host closed the connection]
bitmapper has joined #zig
jukan has joined #zig
jukan_ has quit [Ping timeout: 246 seconds]
dddddd has quit [Ping timeout: 256 seconds]
dddddd has joined #zig
sebonirc has quit [Quit: sebonirc]
earnestly has quit [Ping timeout: 246 seconds]
wilsonk__ has joined #zig
SimonN has quit [Ping timeout: 265 seconds]
jukan has quit [Ping timeout: 264 seconds]
SimonN has joined #zig
dddddd has quit [Ping timeout: 256 seconds]
dddddd has joined #zig
xackus_ has joined #zig
xackus has quit [Ping timeout: 264 seconds]
notzmv has joined #zig
jukan has joined #zig
ur5us has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 264 seconds]
<Xatenev> hello
<Xatenev> even with -O ReleaseFast a simple hello world application seems rather big compared to a c hello world
<Xatenev> can I reduce it even more anyhow or is this the smallest it can get?
<Xatenev> theres also -O ReleaseSmall but its still rather big.
<Xatenev> I thought maybe this was due to llvm being used as compiler infrastructure but iirc clang is also using llvm and it also has a quite small binary size
<Xatenev> it does still seem to have a bunch of strings in there related to runtime checking stuff .. hm
<daurnimator> Xatenev: are you linking libc? -lc
<daurnimator> Xatenev: also if you want a really small binary, consider overriding the panic handler
<Xatenev> daurnimator, thank you, -lc does help a bit, its reducedf from 850 to 650 lines on godbolt
<Xatenev> daurnimator, https://godbolt.org/z/c7vj38
<Xatenev> daurnimator, is there no command line switch to disable all the runtime checking for a build?
<daurnimator> Xatenev: weird... is godbolt adding something after the code we type? https://godbolt.org/z/GdxWv9
<daurnimator> Xatenev: if you don't use error handling things get a little smaller: https://godbolt.org/z/Gc6WTG
<daurnimator> Xatenev: there's a few blog posts around e.g. https://blog.mandejan.nl/posts/smallest-echo.html
<Xatenev> daurnimator, thank you, interesting
mschwaig has quit [Ping timeout: 264 seconds]
leeward has quit [Ping timeout: 246 seconds]
mschwaig has joined #zig
gpanders has quit [Quit: ZNC - https://znc.in]
gpanders has joined #zig
Xatenev has quit [Remote host closed the connection]
jukan has quit [Ping timeout: 260 seconds]
factormystic4 has joined #zig
factormystic has quit [Ping timeout: 240 seconds]
factormystic4 is now known as factormystic
_whitelogger has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
factormystic has quit [Ping timeout: 240 seconds]
gpanders has quit [Ping timeout: 264 seconds]
gpanders has joined #zig
decentpenguin has joined #zig
decentpenguin has quit [Ping timeout: 260 seconds]
sord937 has joined #zig
cole-h has joined #zig
factormystic has joined #zig
jukan has joined #zig
jukan has quit [Ping timeout: 246 seconds]
ur5us has joined #zig
factormystic has quit [Ping timeout: 240 seconds]
cole-h has quit [Ping timeout: 244 seconds]
factormystic has joined #zig
leon-p has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
dfrey has quit [Ping timeout: 265 seconds]
earnestly has joined #zig
xackus has joined #zig
xackus_ has quit [Ping timeout: 246 seconds]
siraben has quit [Quit: Bridge terminating on SIGTERM]
dtz has quit [Quit: Bridge terminating on SIGTERM]
ifreund_ has quit [Quit: Bridge terminating on SIGTERM]
ugla has quit [Quit: Bridge terminating on SIGTERM]
kameliya[m] has quit [Quit: Bridge terminating on SIGTERM]
BaroqueLarouche has quit [Quit: Bridge terminating on SIGTERM]
mtiljeset[m] has quit [Quit: Bridge terminating on SIGTERM]
ziguana[m] has quit [Quit: Bridge terminating on SIGTERM]
fengb has quit [Quit: Bridge terminating on SIGTERM]
jaens[m] has quit [Quit: Bridge terminating on SIGTERM]
vpzom has quit [Quit: Bridge terminating on SIGTERM]
protheory8-new-m has quit [Quit: Bridge terminating on SIGTERM]
Nypsie[m] has quit [Quit: Bridge terminating on SIGTERM]
motiejus has quit [Quit: Bridge terminating on SIGTERM]
pafmaf[m] has quit [Quit: Bridge terminating on SIGTERM]
BitPuffin has quit [Quit: Bridge terminating on SIGTERM]
Snektron has quit [Quit: Bridge terminating on SIGTERM]
midgard has quit [Ping timeout: 246 seconds]
midgard has joined #zig
Snektron has joined #zig
siraben has joined #zig
ugla has joined #zig
ifreund_ has joined #zig
dtz has joined #zig
jaens[m] has joined #zig
motiejus has joined #zig
BitPuffin has joined #zig
pafmaf[m] has joined #zig
kameliya[m] has joined #zig
mtiljeset[m] has joined #zig
Nypsie[m] has joined #zig
vpzom has joined #zig
fengb has joined #zig
protheory8-new-m has joined #zig
ziguana[m] has joined #zig
BaroqueLarouche has joined #zig
dmgk has joined #zig
gazler has joined #zig
hch has left #zig [#zig]
koko has joined #zig
koko has quit [Quit: Ping timeout (120 seconds)]
jukan has joined #zig
jukan has quit [Ping timeout: 246 seconds]
donniewest has joined #zig
cole-h has joined #zig
Ashpool has joined #zig
<Ashpool> Can I have anonymous fields in a packed struct declaration (e.g. to force some padding here and there)?
<ikskuh> Ashpool, no that's not possible
Akuli has joined #zig
<fengb> Not anonymous, but you can insert auto zeroing fields: `packed struct { foo: u7, _pad: u1 = 0 }`
ed_t has joined #zig
<ed_t> how would i handle this error?
<ed_t> var list = ArrayList(i32).init(a);
<ed_t> list.items[70] = 66;
LanceThePants has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<fengb> Are you trying to create a sparse array?
<ed_t> at this point just learning
<ifreund> you need to grow your ArrayList to at least 70 in length first
<ed_t> if I was to create a sparse array what should I use (arrayHash maybe?)
<ed_t> yes I know I need to grow the list NOT to get a runtime error. What I am trying to understand is how to catch it if I do?
<fengb> You can't catch runtime errors
<fengb> You need a preflight check
<ed_t> I could use try and catch errors on the right side of the =, but it does not work on the left side
<ifreund> there's no error that can be caught there
<ifreund> errors are values returned from functions in zig
waleee-cl has joined #zig
<ifreund> there's no function called in that snipped that returns an error
<dutchie> you just have to check the length before you try indexing
<ifreund> you are simply preforming an illegal operation which is safety-checked in "safe" build modes and undefined behavior in release fast/release small
<ed_t> Test [1/1] test "std.ArrayList/ArrayListUnmanaged.insertSlice"... thread 130129 panic: index out of bounds
<ed_t> list.items[70] = 66;
<ed_t> that is what I would like to catch
<ifreund> as I just said, there is no error to catch there
<ed_t> so "index out of bounds" is not an error from a zig perspective
<ifreund> it's a safety checked illegal operation
<ifreund> which causes a panic in debug/release safe build modes
<ed_t> and zig is not providing a way to catch this, unlike most other conditions
<g-w1> catch it by checking it beforehand
tnorth has joined #zig
<ifreund> no, you cannot handle illegal behavior
<ed_t> g-wl yes I can do this list.items.len has the index limit.
<ifreund> you just need to fix your code to not cause it, either by checking the lenght first or resizing the ArrayList
<ed_t> its just not as clean as catching what should be a rare occurance
<ifreund> this should never happen in correct code
<ifreund> that's what illegal behavior means
<ifreund> errors are for things that can occur despite the code being correct
<ifreund> i.e. opening a file failing because there is no such file with the given name
<ed_t> I understand what you are saying - been coding in many many languages for over 40 year. To me, as a zig newbee, this looks like a corner case that would be good to handle.
<ed_t> for instance:
<ed_t> var list = ArrayList(i32).initCapacity(a,74);
<ed_t> list.items[70] = 66;
<ed_t> I know the space is allocated but the arraylist is not grown...
<ifreund> var list = ArrayList(i32).init(a); list.resize(74); list[70] = 66;
<dutchie> (don't forget to `defer list.deinit();` too)
<ifreund> you can also set items.len manually, though that is more error-prone
<companion_cube> what does `list.resize(74)` put in the slots though?
<dutchie> there's also list.expandToCapacity() and list.allocatedSlice()
<dutchie> companion_cube: undefined
<companion_cube> heh, fair enough
<ed_t> (defer is the next line in the test sample) I will need to look at the code in lib/zig/std to understand just what is happening with resize etc. I would expect there should be a way to detect the undefined slots (eg list.items[40] where i have not set a value)
<ifreund> it sounds like you want a HashMap tbh
<ifreund> you can't detect if memory is `undefined` because the value could be literally anything in relase-fast/small build modes
<ifreund> you could store an ArrayList of optional i32s ArrayList(?i32) but that wouldn't be as nice as a hashmap
<dutchie> and you'll have to remember to initialise them to null
<ifreund> ^
<companion_cube> dutchie: I like the approach of languages with closures though
<companion_cube> you'd have `arr.resizeWith(42, |i| i*2);` or something like that
<companion_cube> specify what to put in new slots
<dutchie> there are some methods on ArrayList which let you copy stuff in
<dutchie> otherwise zig prefers an explicit loop
<ifreund> there's appendNTimes() for example
<ed_t> zig test al_test.zig
<ed_t> list.resize(71);
<ed_t> ./al_test.zig:13:13: error: type '@typeInfo(@typeInfo(@TypeOf(std.array_list.ArrayListAligned(i32,null).initCapacity)).Fn.return_type.?).ErrorUnion.error_set!std.array_list.ArrayListAligned(i32,null)' does not support field access
<dutchie> you forgot a try somewhere
<ed_t> why? know I am missing something very basic here
<ed_t> ahh
<ifreund> try list.resize(71);
<ed_t> same thing with the try added
<dutchie> initCapacity needs a try too
<g-w1> no, list is an error union, when creating list, you forgot a try
<dutchie> since it might run out of memory it returns an error union
tnorth has quit [Ping timeout: 260 seconds]
inet56 has joined #zig
inet56 has quit [Quit: Quit]
<ed_t> thanks for help guys - learning a new language is always both a pita and fun...
<ifreund> indeed, you're most welcome :)
kbd has joined #zig
hnOsmium0001 has joined #zig
dvaun has joined #zig
cole-h has quit [Quit: Goodbye]
cole-h has joined #zig
jukan has joined #zig
ZealousWombat has joined #zig
ZealousWombat has quit [Quit: Connection closed]
<Gliptic> is there some established support/pattern for generating .zig files in build.zig and caching them when inputs don't change?
zags has joined #zig
<zags> Hey. I'm taking a 32 byte piece of data as 64-char hex bytes from the command line. What's the best way to convert the hex string to a slice of 32 bytes?
<zags> array*
<ikskuh> var bytes: [32]u8 = undefined;
<ikskuh> for(bytes) |*b,i| { b.* = try std.fmt.parseInt(u8, string_slice[2*i..2+(i+i)], 16); }
<zags> oof, no fromHex? :D
<zags> I'll try that
<zags> thanks
<ikskuh> it's not that much code ^^
<zags> it is when you do it a lot, but i'll make a wrapper
xackus has quit [Ping timeout: 265 seconds]
<zags> pub fn fromHex(in: []const u8, out: *[32]u8) !void {
<zags> for(out) |*b,i| {
<zags> }
<zags> b.* = try std.fmt.parseInt(u8, in[2*i..2+(i+i)], 16);
<zags> }Is that a fine signature?
<ikskuh> zags: "in: *const[64] u8"
<zags> Not familiar with all the idioms yet
<zags> ikskuh: good point!
<ikskuh> you know how long the input string must be :)
<zags> wait, why pointer and not just the slice for input?
<ikskuh> because a slice has dynamic length
<ikskuh> and you'd have an out-of-range error
<zags> but it worked :D
<ikskuh> yes, for exactly one input ;)
<ikskuh> try passing it "foo"
<ikskuh> and it will crash
<ikskuh> with the signature taking a const pointer to an array of 64 chars
<ikskuh> you enforce psasing the right amount of chars
<zags> i see, thanks
<ikskuh> note:
<ikskuh> slicing with comptime known lengths yield pointers to arrays
<ikskuh> so
<ikskuh> dynamic_slice[0..64] will return "*const [64]u8" and not "[]const u8"
<zags> love it
<ikskuh> it's absolutely rad
<ikskuh> if you get the implications :D
<ikskuh> dynamic_slice[0..3].* = other_dynamic_slice[4..8].*
<zags> ikskuh: how would you write a general fromHex, taking hex strings of any length. Then I guess there's the question of allocation as well.
<ikskuh> dynamic or static length?
<zags> length unknown, input from user
<ikskuh> requires an allocator
<zags> typically you have that passed in then?
<ikskuh> fn fromHexAlloc(allocator: *std.mem.Allocator, input: []const u8) ![]u8
<zags> or require preallocated output?
<zags> Ok, so who frees though when passing allocator?
<zags> if it's an arena, it's simple, but...
<zags> in general
<ikskuh> the caller
<ikskuh> owns the memory
<ikskuh> they decide when to free
<ikskuh> fromHex(dest: []u8, input: []const u8) !usize
<ikskuh> would be a idiomatic fixed version
<ikskuh> fromHexStatic(comptime N: usize, dest: *const [N]u8, input: *const [2*N]u8) !void
* zags takes notes
<zags> these hex conversions are so frequent, would be nice if std had them imo even if it's not much code
* ikskuh loves the type system a lot
<ikskuh> zags: i required them once ^^
<zags> i do it all the time in various projects hah
<ikskuh> but nobody prevents you from making a nice pr for std.fmt :)
<zags> :)
<Ashpool> Is there a way to declare a function that expects a generic type, e.g. a generic std.io.Writer?
<Ashpool> as an argument.
<ikskuh> use anytype
<ikskuh> fn takesWriter(writer: anytype) !void
<zags> So I take it std.fmt doesn't have a nice way to print arrays as hex strings?
<zags> the other way around, that is
<ikskuh> {h}
<ikskuh> ah no
<ikskuh> {x} and {X}
<ikskuh> sorry :D
<zags> ooooh nice
<zags> std.debug.print("{X}\n", .{.bytes}); I added .bytes instead of bytes by mistake and it printed ".bytes".... how does that happen
<ikskuh> because a enum literal doesn't have a X specifier
<ikskuh> but using non-existing specifiers doesn't error
<zags> right same if I do {}
tdeo has quit [Read error: Connection reset by peer]
tdeo has joined #zig
dddddd_ has joined #zig
dddddd has quit [Ping timeout: 256 seconds]
<ed_t> are if always fully evaluated or does the evaluation stop when the result if fixed (conditional evaluation if I remember correctly)?
<ikskuh> ed_t: zig will only semantically check branches if their result is either comptime-taken or runtime known
<ikskuh> if(true) { } else { }
<ikskuh> only the true-part will be analyzed
<ikskuh> if(false) { } else { } is the other way round
<ed_t> so what gets evaluated in if ( e1 and e2 and e3 )
<ikskuh> if(runtime_value) { } else { } will analyze both
<ed_t> when e1 is true and e2 is false
<ikskuh> ed_t: is that related to if or boolean operators? :D
<ikskuh> i think its the latter
<ikskuh> and/or are guarantted to be short-circuited
<ikskuh> so
<ikskuh> f() and g() will run g() only when f() returns true
<ed_t> thats what i was looking for. Thanks
<ikskuh> note that you can recognize this by the fact that "and" and "or" are keywords and not symbol operators
<ikskuh> everything that is control flow in zig is required to be a keyword
nvmd has quit [Ping timeout: 260 seconds]
nvmd has joined #zig
<dvaun> I'm enjoying the conversation here and really dig Zig so far. Problem is I've never done much with manual memory management, allocators...does anyone have any favorite/recommended resources for playing around like this? :) if not I'll scour through lobsters, HN etc...
<justin_smith> dvaun: something that helps a lot is using container structs like std.ArrayList and std.AutoHashMap which are parameterized with a type and allocator
<earnestly> dvaun: Have you opened files before, network connections, etc? It's not a million miles from that, with the same lifetime considerations
<zags> dvaun: I think it's best to just write a bunch of small programs to test things out, that's what I'm doing now. I haven't done manual mgmt in a while, so need to rediscover good idioms. Smart pointers and GC makes you lazy :D
<justin_smith> oh, and definitely use "defer" with a deallocation after every explicit allocation (unless your allocation is returned / assigned to another scope)
<dvaun> earnestly: yes, using higher languages e.g. C#, python
<dvaun> zags: it's been a while since I've used any pointers ;)
<dvaun> I did see that defer pattern. Thank you for the reminder.
<justin_smith> I think that's a good comparison, but the gotcha is that the world is full of python programs that don't close their files properly, but the program is just accidentally used in such a way that the error is never visible
<ikskuh> dvaun: memory is just a resource like files. you open/allocate, so you have to close/free the resource
<dvaun> See, I've been considering playing with either Rust or Zig for some hobby projects and to get back into lower-level dev. It just seems fun and interesting compared to my work (which is primarily SQL atm so no real work on building tools etc...)
<justin_smith> with allocations, this is more likely to be a showstopper
<earnestly> dvaun: It's the same mental model. resources need to be aquired and then released. Opened files and sockets need to be closed, etc. Which thread has access to read/write, etc.
<dvaun> that makes sense ikskuh and earnestly .
<dvaun> back when I played with C++ in college I enjoyed going through Beej's guide...might try going through that again but with Zig and mess around.
<dvaun> also looking at writing a simple allocator. Might look for an OS dev book to get fundamentals down again
<dvaun> thanks for the suggestions everyone :)
<justin_smith> dvaun: also with "zig test" you can get errors from allocated memory that isn't freed
<dvaun> that's great
<dvaun> You know what I really enjoy so far? Someone in the community created https://ziglang.org and it's been quite a nice walkthrough with the language features
<Nypsie[m]> ziglang.org is the official website. Do you maybe mean ziglearn.org? :)
<dvaun> yes! that :P
<zags> embarrasing... how do I turn var r: u64 into a []const u8?
<zags> using an api that takes the latter
<dvaun> these are the questions/problems that I need to play around with and become comfortable with :P
<fengb> zags: std.fmt.bufPrint(target_buf, "{d}", .{r})
<g-w1> do you want to just get the bytes?
<zags> yeah
<ikskuh> std.mem.asBytes
<zags> oh
<fengb> Bytes or string format output?
<zags> bytes
<fengb> I suppose I should have asked that :P
<zags> I yeah wasn't clear, need the 8 bytes
<zags> alright, std.mem.nativeToBig and then asBytes does the trick
<zags> asBytes with endian would be stellar, but hey
<zags> because now I need a temporary in client code
<ikskuh> zags: asByte is pretty much zero-cost
<fengb> Ah endianness
<zags> yeah this hits network :)
<fengb> Well if you don't transform it and the other side is the same implementation, it'll probably be fine 🙃
<zags> which by four decades old convention is big endian when everything else is little endian
<zags> fengb: the protocol at hand requires network order
<ikskuh> zags: that's unfortunate
<zags> very common :)
<ikskuh> yeah
<ikskuh> if you want to create network packets
<ikskuh> or decode them
<ikskuh> look at std.mem.readIntBig and std.mem.writeIntBig
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<zags> ikskuh: yeah, those look cool, in this case I need asBytes as I have to hash some stuff in network order before serializing
ur5us has joined #zig
r0bby has quit [Ping timeout: 272 seconds]
tracernz has quit [Read error: Connection reset by peer]
tracernz has joined #zig
r0bby has joined #zig
<dvaun> hm anyone know of any site that has a search interface for looking through std?
<dvaun> going through the std folder right now checking out the files
<ikskuh> dvaun: i usually just browse it with my system tools (find, grep, vscode)
<dvaun> grep would be useful
<ikskuh> you on windows or unix?
<dvaun> atm mac but my home machine is windows
<ikskuh> ah
<dvaun> i'd run debian but my wife would contest
<ikskuh> dualboot!
<ikskuh> but more seriously: i just use vscode for that
<dvaun> might do that in the future
<g-w1> here, but it is VERY incomplete https://ziglang.org/documentation/master/std/
<dvaun> I need to figure out how to run Plex in linux while retaining gpu transcoding ability
<dvaun> g-w1: ooh much appreciated!
<dvaun> I was skipping around the nav on the main site...didn't click on the documentation link
<dvaun> alright I'll retain the RTFM-esque questions for the foreseeable time...thanks
<zags> dvaun: yeah vscode is highly recommended - just git clone the zig repo and open in vscode. Makes it super easy to navigate through the source.
<g-w1> but I wouldn't use it. the auto docs tool is very old and there is a design flaw in it (lazy analysis).
<g-w1> *wouldn't use the website
<dvaun> zags: I have found the vscode integration to be quite nice for Zig in general. I got ZLS working by building from source (I don't have admin on this machine) and have been playing around since.
<zags> yep, zls works great
<zags> for the most part
<justin_smith> is there a cloc or cloc workalike configured for zig?
<justin_smith> maybe there's a file I can throw in /etc/ somewhere to make cloc count zig files
<ikskuh> scc can do this
<dvaun> ikskuh: is scc this library? https://github.com/boyter/scc
<ikskuh> yes
<justin_smith> ikskuh: ahh, turns out I was using obsolete tools, thanks
ur5us_ has joined #zig
<dvaun> interesting
<dvaun> in std.os there is getRandomBytesDevURandom. Maybe this is a stupid question...is it safe to not check for the builtin.os.tag to be linux or bsd since it's assumed you'd only call it when in those OSes?
<ikskuh> yes
<ikskuh> it won't compile on other platforms
<dvaun> ah, gotcha
<ikskuh> if you need random, check out std.rand ;)
<dvaun> oh, noted that openZ handles it
<dvaun> nevermind
<ikskuh> there is a Prng and a crypto provider
ur5us has quit [Ping timeout: 264 seconds]
<dvaun> bouncing off that recommendation...(looking at the Random struct)...i really do like the `Self = @This()` idiom
<ikskuh> :D
<dvaun> brings me to thinking of a way to create some async functions which execute after returning something like e.g. a promise (thinking JavaScript here)
<dvaun> overall Zig is much cleaner than C
<dvaun> imo
<ikskuh> we have that already :)
<ikskuh> var promise = await someFunc();
<dvaun> ooh boy that's better :)
<ikskuh> var result = await promise;
<dvaun> i can think of a fun use case
<dvaun> like making some server which can optionally add guards and other checks to a request
<dvaun> anyway, thanks for the input :D might practice by rewriting some other tools into Zig and seeing if tests pass
<ikskuh> have fun :)
<dvaun> crypto is always fun. Might look at xxhash
<ikskuh> running tests with zig is always fun
<ikskuh> btw, zigs crypto is pretty good already i think
<ikskuh> we have a crypto pro contributor
<dvaun> that's awesome!
<dvaun> i'm no pro at any of these fields. I'm pretty new, only a few years under my belt
<dvaun> they're just fun to read about :) I spend most of my time reading
<ikskuh> you know libsodium?
<dvaun> yes
<ikskuh> frank is writing zig crypto libs as well
<ikskuh> which is very cool
<dvaun> was he the author of libsodium or nacl?
<g-w1> yes
<dvaun> sorry, I don't know big contributors by name
<dvaun> that's really cool
<ikskuh> he's that dude :D
<dvaun> that's awesome
<dvaun> i'm sure it exists, but it'd be neat to play with something similar to the DPAPI in windows for encrypting data and memory per user, process session etc.
<dvaun> i'm not familiar with POSIX internals beyond the basics lol
<zags> dvaun: windows is way ahead of the curve there, other os's offer various keychain apps
<zags> stuff like libsecret is not fun in comparison
<ed_t> what is zig trying to tell me here?
<ed_t> error: variable of type 'type' must be const or comptime
<ed_t> var hash = [4096][4096]u32;
<mikdusan> `var hash: [4096][4096]u32 = undefined;`
<ed_t> thanks
<ed_t> that was it
<zags> int x = reinterpret_cast<decltype(x)>(5); works in c++, ie. x can be refered to on the RHS
<zags> var x: u64 = @intCast(@TypeOf(x), 5); fails to compile because x is undeclared
<zags> What was the reason for this?
<justin_smith> zags: "var x: u64 = 5;" - or maybe I'm missing your point?
<mikdusan> i'd hazard a guess that no compelling case was made to allow referring to lhs this type during it's own init
<zags> justin_smith: it's a silly example, the point is to be able to use LHS in @TypeOf expressions on RHS
<justin_smith> zags: fair, yeah the clear thing is zig doesn't allow that, I can't answer any deeper than that personally
<zags> slightly annoying, not a big deal
<zags> porting some code that does this
<mikdusan> what does c++ do if `auto x = ... decltype(x) ...;`
<ikskuh> mikdusan: magic :D
<zags> that wouldn't work
<zags> because it's use before deduction
<zags> iow, compile error
notzmv has quit [Ping timeout: 265 seconds]
<ed_t> if you have an array of a structure, can you do &a[88].field ?
<Gliptic> that's a pointer to the field of the 88th element
<ed_t> yes
<Gliptic> then yes
<ed_t> any idea why this happens then?
<ed_t> error: expected type '*u32', found '*i32'
<ed_t> l = &heap.items[i].n;
<Gliptic> l is of *u32 type?
<Gliptic> but .n is i32
<ed_t> no. as a pointer l is i32
<ed_t> as I understand things (I am a zig newbie)
<Gliptic> I meant the other way around
<Gliptic> possibly..
<Gliptic> I mean, what type is .n?
<ed_t> u32
<Gliptic> well, yeah
<Gliptic> you can't assign a *u32 to a *i32
<ed_t> but & should give me an address so I should get the address of head.times[i].n
<ed_t> or I need to tell zig that l is a pointer the u32 values
<Gliptic> it's not just "an address", it's a specifically typed pointer
<Gliptic> you need to change either l or .n so that the types match
<Gliptic> changing l to *u32 is one option
<ed_t> how would I define l as a pointer to u32?
<Gliptic> how is it defined now?
<ed_t> var l = &hash[x][y];
<Gliptic> well, then you need to change 'hash' as well
<ed_t> hash is an array of u32
<ed_t> (s)
<Gliptic> array of array of u32?
<ed_t> yes
<Gliptic> that's odd, because then l should have been *u32
<Gliptic> are you sure it's not .n that is i32?
<ed_t> that is what I thought
<ed_t> n: i32,
<Gliptic> yeah
<ed_t> is was suposed to be u32
<Gliptic> there's your problem
<ed_t> thanks. new lang = new errors to learn
gazler has quit [Read error: Connection reset by peer]
gazler has joined #zig
midgard_ has joined #zig
<ed_t> how do i coerce usize to u32, I know it can overflow so I guess try will be involved?
gazler_ has joined #zig
midgard has quit [Ping timeout: 260 seconds]
gazler has quit [Ping timeout: 260 seconds]
sord937 has quit [Quit: sord937]
<ed_t> @intCast(u32, heap.items.len)
<g-w1> @truncate
<dvaun> is struct really self-defined as in src/type/Struct.zig or am I missing some other file?
<dvaun> base: Type.Payload = .{ .tag = .@"struct" },`
<dvaun> what caught my eye is `
Akuli has quit [Quit: Leaving]
<g-w1> no, that is the self hosted compiler, you want src/stage1/all_types.zig:1411
<dvaun> ah, much appreciated
<dvaun> codegen.cpp, line 406 under stage1
<dvaun> > // This whole function should be burned to the ground
<dvaun> lol
<g-w1> yep, stage2 will replace it
donniewest has quit [Quit: WeeChat 3.0]
<daurnimator> ehhhhhh
<Ashpool> Is there a way to link libc statically?
<fengb> On Linux, you can use target x86_64-linux-musl
<andrewrk> check it out: struct-of-arrays implemented in userland, with an API roughly the same as ArrayList
<andrewrk> there's an impl by ifreund there and then my counter proposal to make the implementation only use 1 allocation for everything
<andrewrk> featuring a call to std.sort.sort at comptime
<daurnimator> // workaround for stage1 compiler bug ? which bug is that
<andrewrk> it crashed in the comptime function evaluation memoization code
zags has quit [Ping timeout: 264 seconds]
sebonirc has joined #zig
ifreund has quit [Ping timeout: 256 seconds]
ifreund has joined #zig
Ashpool has quit [Quit: Leaving]