1
QB64 Discussion / Question about DIMing user-defined types
« on: March 03, 2021, 05:45:36 pm »
Hi everybody, I had a quick question about DIM and how it works with user-defined types.
Say I create a type for a 3d point,
When I DIM something of this type, can I safely assume that it will always DIM the type with defaulted values (x = 0, y = 0, z = 0), or is there a chance that the program will reuse some bits of memory, and end up with my x, y or z variables equaling something other than 0? The superstitious part of me wants to do something like this to ensure that my variables always get set up properly:
So my question is, in general: when you DIM a user defined type, does the program make sure to reset all of the bits and whatnot in memory, or does it just dimension the variable without looking at whether there was already some stuff there in memory? My thinking is that it will actually reset the memory when it DIMs any variable, but I wasn't quite sure.
Say I create a type for a 3d point,
Code: QB64: [Select]
When I DIM something of this type, can I safely assume that it will always DIM the type with defaulted values (x = 0, y = 0, z = 0), or is there a chance that the program will reuse some bits of memory, and end up with my x, y or z variables equaling something other than 0? The superstitious part of me wants to do something like this to ensure that my variables always get set up properly:
Code: QB64: [Select]
- ' Set up some "default" variable at the beginning of the script...
- vec3_default.x = 0
- vec3_default.y = 0
- vec3_default.z = 0
- ' And use that default variable to initialize any DIMed variable
- someRandomPoint = vec3_default
So my question is, in general: when you DIM a user defined type, does the program make sure to reset all of the bits and whatnot in memory, or does it just dimension the variable without looking at whether there was already some stuff there in memory? My thinking is that it will actually reset the memory when it DIMs any variable, but I wasn't quite sure.