Zig NEWS

Discussion on: What's a String Literal in Zig?

Collapse
 
mrkishi profile image
mrkishi

I believe all consts end up on static data sections, not only strings.

Check it out on Godbolt.

Collapse
 
kristoff profile image
Loris Cro

Uh, interesting, I'll investingate a little bit and edit the wording. Thanks for pointing that out!

Collapse
 
mrkishi profile image
mrkishi

Cheers!

In case anyone is following along, I updated the example to better demonstrate where consts end up in memory: godbolt.org/z/jM75hf5b9.

I don't know whether Zig provides a way to check what kind of memory a pointer points to, or if it exposes sections' addresses (eg. gcc's end, edata and etext), but note how get_ptr_static basically returns the address of an unnamed label, which is before the heap (and way before the stack, which grows downwards).