#Lifetimes on the stack
42 messages ยท Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
are the members of vec3 of type float or double?
Paste code as text.
My bad, will do that instead
floats
typedef struct
{
float x;
float y;
float z;
} vec3;
the code is fine then
It doesn't matter here, does it?
it would work fine with double
if it was int then the format strings would be incorrect
Each vec3s will be in different, non-overlapping memory locations if that's what you're asking
Gotcha, as long as it's native types it would work I assume?
'native type'?
My bad, not sure what the correct name is
You mentioned float and double though.
Basically the types that come out of the box with the language
So unless you have another code somewhere that invades another function's stack and overwrites them, your code should be 100% fine
yes, because it would be correct if it was one of those types
OK I took that as picking one out of those two.
Gotcha, it was basically that yeah
that doesn't really change anything
you're copying the vec3 into the array
Aaaah
Alright, that's what I needed to hear, makes a lot more sense now
So it inserts a copy into the array
Didn't know that, thank you
yep = with structures will copy the structures (i.e. it copies all of the members)
Gotcha, that answers my question, I was worried it would've copied the reference somehow, which would mess up the code once out of scope
Not the code, the array I mean
The compiler is allowed to optimize away that a by just directly writing data into vecs, but in essence you can think of it as a copy
That's nice, thank you all :)
the compiler can theoretically optimize out the entire array and just do one big printf call 
There's really no way to tell what the compiler does with your code I think lmao
Just don't do UB and the compiler won't ever break your code
yeah, you shouldn't really concern yourself with optimizations when thinking about the semantics of the language; i.e. it does a copy but the way it reaches the result of copying (or the entire program in general) is up to the compiler
I think compiler optimizations are beyond my skillset right now ๐๐๐ But I'll have to learn them soon enough considering my 3d engine project
It's running well but I doubt it will with millions of polygons
Either way, thank you so much for the help :)
I really appreciate it