chibill has quit [Remote host closed the connection]
sham1 has quit [Write error: Connection reset by peer]
jcmdln has quit [Read error: Connection reset by peer]
selfsigned has quit [Remote host closed the connection]
raggi has quit [Read error: Connection reset by peer]
Irvise_ has quit [Write error: Connection reset by peer]
sakasama has quit [Read error: Connection reset by peer]
kivikakk has quit [Write error: Connection reset by peer]
sakasama has joined #osdev
wlemuel has quit [Ping timeout: 240 seconds]
vdamewood has quit [Quit: Life beckons]
sham1 has joined #osdev
Irvise_ has joined #osdev
raggi has joined #osdev
jcmdln has joined #osdev
kivikakk has joined #osdev
chibill has joined #osdev
selfsigned has joined #osdev
wlemuel has joined #osdev
bnchs has quit [Remote host closed the connection]
bradd has quit [Ping timeout: 255 seconds]
DynamiteDan has quit [Excess Flood]
DynamiteDan has joined #osdev
Halofreak1990 has joined #osdev
Halofreak1990 has quit [Ping timeout: 240 seconds]
joe9 has joined #osdev
bauen1 has joined #osdev
Halofreak1990 has joined #osdev
<zid`>
Man, coming up with non-contrived examples to teach beginners pointers is difficult
<zid`>
I keep ending up with code that could just be replaced by n = f(n) where n isn't a pointer to begin with too
bauen1 has quit [Ping timeout: 250 seconds]
<zid`>
"what about errors?" "I could just put the { printf("invalid banan"); abort(1); } prt inside the function though?"
<nortti>
are you teaching them before or after teaching about arrays?
<zid`>
arrays needing pointers in C is actually just a weird artefact of the type system, but I feel I will have to do it that way next
<zid`>
a[b] being implemented as *(a+b) rather than arrays being full types
<nortti>
oh, was asking because you can't return arrays
<zid`>
yea exactly why arrays *will* be useful here
<zid`>
f(a1, a2, a3, a4, ..) vs strings
<zid`>
and can't return arrays, etc
Halofreak1990 has quit [Ping timeout: 248 seconds]
<zid`>
I would like to think of a real example for what pointers are actually useful for though, making programs "dynamic"
bauen1 has joined #osdev
bauen1 has quit [Ping timeout: 240 seconds]
bauen1 has joined #osdev
sjs has quit [Ping timeout: 276 seconds]
sjs has joined #osdev
bauen1 has quit [Ping timeout: 276 seconds]
bauen1 has joined #osdev
<epony>
you mean position independent
<epony>
time to find out about address modes
<Mutabah>
zid`: strings?
<Mutabah>
being pointers to the text data
<zid`>
yea strings is arrays
bauen1 has quit [Ping timeout: 276 seconds]
<sham1>
The reason why C arrays feel fake is because they don't really know their own sizes. And how could they? The language was designed at a time when memory was a luxury. No need to store the size of an array, are you mad‽
<sham1>
And as for now, can't change it since it might just break just about everything
<Mutabah>
zid`: strings are dynamically sized arrays
<Mutabah>
another option, you could use multiple outputs? using output pointers
<Mutabah>
maybe a division function? takes numerator and denominator, and stores the quotient and remainder in the output... and returns a boolean that is false if the division failed (i.e. zero denominator)
<zid`>
You can use a struct
<zid`>
structs are lvalues
<zid`>
but maybe this is just a thing in general
<zid`>
we're all addicted to using explicit pointers when a lot of the time we could just write x = f(x) instead
<zid`>
I wouldn't want to, for complicated reasons, but it's hard to briefly explain that to an amateur
<sham1>
If you know how many things you need to return, yes. C does have stuff like div_t for this
<Mutabah>
zid`: returning a struct is the better higher-level approach, but at the CPU level anything larger than two registers will most likely end up as a pointer
<zid`>
>amateur
<Mutabah>
Strings/lists are the best option really
<Mutabah>
handling a runtime-determined number of items
Jari-- has joined #osdev
<sham1>
"I don't want this to move, so I allocated it manually and now to effectively make use of it, I need to use the pointer to it"
<zid`>
yea it not needing to move is the sort of example I need
<zid`>
but I need it to be simple as possible
<sham1>
Since C ofc is pass-by-value
<zid`>
not in the bowels of a program
<Mutabah>
A massive struct?
<Mutabah>
it's not efficient (or even convinent) to do `mystate = foo(mystate)`, so you do `foo(&mystate)`
<sham1>
"I need a reference to this object from elsewhere, and the reference has to stay valid and the object needs to update, so I need this pointer so it doesn't move, while allowing me to manipulate it"
<zid`>
Mutabah: detail I'd have to eplain
<zid`>
and, compilers will optimize it to a pointer internally
<zid`>
like, they can't not, it's per the abi
elastic_dog has quit [Ping timeout: 246 seconds]
<sham1>
Do the beginners you're talking to know any other languages?
elastic_dog has joined #osdev
<Mutabah>
zid`: I'm more thinking ergonomics... `foo` is just editing `mystate`
<Mutabah>
why should it have to take it and return it, it could just "walk over there and fiddle with it"
slidercrank has quit [Ping timeout: 255 seconds]
<sham1>
Well mystate = foo(mystate) makes more sense and is probably easier to reason about, since it just returns a fresh state, like how you'd do it in functional programming. That it gets optimised to the pointer version is an implementation detail
<Mutabah>
Meanwhile, the `foo(&mystate)` way is the "OOP" way
<sham1>
Well imperative, but yes
<Mutabah>
*shrug*
<Mutabah>
zid`: strings or other dynamic-sized arrays
<Mutabah>
You could avoid the NUL termination challenges of C strings and just use an explicit length in the example
<GeDaMo>
zid`: maybe trees as an example for pointers?
<gog>
what's a tree
<GeDaMo>
A recursive data structure :P
<gog>
oh
<GeDaMo>
On the other hand, that might involve explaining recursion :|
<gog>
i thought it was a graph with no cycles
<Mutabah>
Trees are strictly diverging graphs
<gog>
me too
<Ermine>
gog: I turned out to lack any stuff supporting fiber cabels, so I agree for some copper
<gog>
great! you may pet me and buy my copper
* Ermine
buys copper from gog and pets her
<zid`>
don't trust gog'nasir
<zid`>
noo Ermine
* Ermine
enters copper age
<zid`>
you wish
<gog>
wooo
<gog>
idk why that meme kills me
<gog>
there's another one about a guy who watched a donkey eating figs and he thought it was so funny after he said "maybe we should get him some wine too" and he laughed so hard he died
<gog>
idk if this is a real story from history
<nortti>
chrysippus of soli?
<nortti>
"Diogenes Laërtius gives two different accounts of his death.[18] In the first account, Chrysippus was seized with dizziness having drunk undiluted wine at a feast, and died soon after. In the second account, he was watching a donkey eat some figs and cried out: "Now give the donkey a drink of pure wine to wash down the figs", whereupon he died in a fit of laughter."
<gog>
yes
<zid`>
You are standing in my light go away.
<GeDaMo>
"The episode is infamous for the documented example of a man laughing to death. Fifty-year-old Alex Mitchell could not stop laughing for a continuous 25-minute period—almost the entire length of the show—and suffered a fatal heart attack as a result of the strain placed on his heart. Alex's widow later sent the Goodies a letter thanking them for making his final moments so pleasant." https://en.wikipedia.org/wiki/Kung_Fu_Kapers
bauen1 has joined #osdev
<sakasama>
zid` Basic data structures are great for teaching pointers: linked lists, spaghetti stack and trees. They're also good examples of why iteration might need more than array offsets.
<zid`>
mmm sorta
<zid`>
people tend to get bogged down in the actual details, I will get there
<zid`>
once pointers are slightly more comfortable
<gog>
what's a spaghetti stack
<Ermine>
Tfw your joke is too good
<zid`>
The other weird death thing I remember is tycho brhaehaeh dying from needing a piss
<zid`>
cus he refused to have to excuse himself at a fancy dinner
bauen1 has quit [Ping timeout: 240 seconds]
<zid`>
the astronomer guy
<zid`>
with the nose?
bauen1 has joined #osdev
<Ermine>
zid`: it's one of the versions
<zid`>
w're baktracking into initialization vs assignment atm
<zid`>
because I brought up arrays not being lvalues
<zid`>
slow and steady :D
<zid`>
he's thinking it all through at least
* sakasama
stacks spaghetti over gog.
<gog>
i've died from needing a piss
* gog
eats spaghetti
<zid`>
I've died from pissing too much
<zid`>
Old age.
<sakasama>
The mortality rates here are terrible.
<zid`>
It's the air quality I think
<sakasama>
Too much cheap copper dust.
<zid`>
if it's even really copper
<zid`>
who knows with gog'nasir roaming around
<gog>
it's mostly fired clay with copper plating
<zid`>
shh
<zid`>
The correct answer is "It was fine when I sold it"
<zid`>
"I'd be asking questions to the courier, not me"
<zid`>
Where my E2th element of E1 bitches at
Matt|home has joined #osdev
<Ermine>
Do people die from being pissed off?
<zid`>
yes
<zid`>
it's called blowing a head gasket
joe9 has quit [Quit: leaving]
joe9 has joined #osdev
<gog>
ok i'm just starting now to work with EF.Core
<gog>
and it's so freakin nice
<gog>
omg
<gog>
we don't have to run a big fragile program to generate shitloads of bad code for us anymore
<gog>
i love it
<gog>
microsoft makes decent products sometimes
<gog>
not windows
<gog>
the NT kernel yes
<gog>
windows, no
<zid`>
I actually really like win32
<gog>
i've never coded with it really
<zid`>
Just pick what you wanna do, write that sentence and end it with ()
<zid`>
that function exists and has a sane interface (usually)
<zid`>
I want to create a window..? Sure, CreateWindow()
<zid`>
I want to.. enumerate.. the .. monitors?
<zid`>
Sure, EnumMonitors()
<zid`>
I want to .. create a file? SUre. OpenFile.
<zid`>
(wait what)
<gog>
MapViewOfFile
<Ermine>
gog: is EF.Core js framework?
<gog>
c#
<gog>
dotnet
gildasio has quit [Remote host closed the connection]
<zid`>
Fun fact, my stack explodes at f(64908) if I write recursive return f(x+1)
<zid`>
so I assume windows has.. 128k stacks?
<zid`>
err 256k
gildasio has joined #osdev
<zid`>
err even bigger cus return address and alignment..
<zid`>
1MB!?
Left_Turn has joined #osdev
<geist>
that seems reasonable, yes
<geist>
actually 1MB may be a little small for the default stack
<zid`>
1MB is beyond reasonable
<geist>
mkay
<geist>
i've seen much larger than that. pretty sre linux defaults to something somehwat bigger than even that
<geist>
for the first stack at least
xenos1984 has quit [Ping timeout: 240 seconds]
<zid`>
mine's 8kB or 8MB I can't tell
<zid`>
it jsut says 'size 8192'
<geist>
yah 8MB
<geist>
lots of code just assumes you can use fairly large amount of stack in main() in a single threaded app
<geist>
makes sense, create a few objects on the stack, call into a pile of code that performs a task with it
<geist>
no heap, gets it done
<zid`>
I assume "lots of C++ programs in their constructors", more than anything
<zid`>
is what caused beeg stack
<zid`>
to be historicallyt rue
<geist>
possibly, but i'd also histrically say a lot of C code can do that
<geist>
though i guess historicially C code would probably make a lot of globals
<geist>
but in a single threaded, classic enviroment, the stack would be The Stack and it'd grow down from the top of the address space, and you'd have basically as much stack as you have memory in the system
slidercrank has joined #osdev
<geist>
actually linux has this pretty grody scheme where it can dynamically grow the stack mapping automatically in the kernel
<gog>
dynamic stacks!
<geist>
it's pretty nasty. someone was asking about something equivalent in zircon and it was like ugh no way
<nortti>
is it the stack probe thing, or something else?
heat has joined #osdev
<gog>
heat
<gog>
heat heat heat
<heat>
hi
heat has quit [Remote host closed the connection]
<gog>
:<
heat has joined #osdev
<heat>
oh yes good ol ping timeout
<zid`>
I accidntally just tail call optimized my example use of a software stack
<zid`>
so it never goes deeper than 1 element
<zid`>
I'm TOO GOOD AT PROGRAMMING
<heat>
i'm having easily the worst weeks of my life
<heat>
checkmate atheist
<geist>
nortti: i think it's stack probe? something like if you fault within some certain distance of the bottom of a stack mapping, it'll just expand the stack mapping
<zid`>
heat have you tried staring at some footballers' legs, that usually cheers you up
<heat>
i'm afraid that doesn't help atm
<gog>
what's the matter, buddY?
zxrom has joined #osdev
<zid`>
gog'nasir has some copper to gift you
xenos1984 has joined #osdev
gog has quit [Quit: Konversation terminated!]
qubasa has quit [Remote host closed the connection]
xenos1984 has quit [Ping timeout: 248 seconds]
<heat>
geist, musl has historically had issues with its small thread stacks (80k, then bumped to 128k)
<heat>
while glibc uses RLIMIT_STACK so you get a multi-megabyte stack
<geist>
yeah and also i remember hearing about some sort of feature/extension where an ELF section declares the size of the initial stack, if you want to override it
<geist>
i dunno what loaders honor it though
<heat>
yes, they sometimes use GNU_STACK for it
<heat>
program header
xvmt has quit [Remote host closed the connection]
<geist>
yah gues you’d use that if you had exceptional needs
<heat>
linux does not seem to honor the size, although it does honor the perms (for the executable bit)
<geist>
glibc doesn’t?
<geist>
or you’re using something otherthan glibc?
<heat>
i'm looking at the codez. saying that the kernel's elf loader does not look at the size in PT_GNU_STACK
<geist>
ah but seems like the ld.so loader could probably honor it and then switch to the newer stack
<geist>
since doesn’t the kernel loader just load ld.so?
<heat>
yes
xenos1984 has joined #osdev
<heat>
ldso does re-mprotect the stack if the perms don't match up
<heat>
actually no, they do not seem to use any GNU_STACK stuff for sizing. huh.
<bslsk05>
git.musl-libc.org: musl - musl - an implementation of the standard library for Linux-based systems
<geist>
yah that’s probably where i heard about it, because fuchsia uses a fork of musl, we probably also picked up the feature
<geist>
makes sense, look like it finds the max of the main program and all the dynamic libs that it knows about
FreeFull has joined #osdev
qubasa has joined #osdev
<heat>
i'm seriously surprised you didn't just take another much larger stack size for threads
dude12312414 has joined #osdev
<heat>
i don't see much reasoning for small thread stacks in fuchsia. you can only make the case for address space exhaustion (on 32-bit) and systems without overcommit
<ChadGPT>
how small is small
Halofreak1990 has joined #osdev
<heat>
musl used 80k and bumped them up to 128
<ChadGPT>
huh
bauen1 has quit [Ping timeout: 265 seconds]
<heat>
zircon uses 256KB by default but does respect PT_GNU_STACK