in fact I'm looking to know if floats under amiga are 32 bits length (like int) or not .. And to be sure on how I can read/write float on memory using pointers ...
Can someone give some short commented examples ?
Thank you.
Kindest Regards, Fred
All we have to decide is what to do with the time that is given to us.
In C programming, float is always 32-bit and double is always 64-bit, regardless of what architecture you're coding on.
You have to be careful with pointers. Since both int and float have the same data size (32 bits) the processor has the same alignment restrictions, which means you can write float data into an int and vice versa (not sure why you want to do that though).
The question that should have been posed is: what are you trying to achieve / do? And by that I don't mean "setup a pointer to an int and use it to put a float32 inside memory", but why do you need to do that?
@DaveAE I allocate a block of memory to store object meshes in float and integer format... Why ?
Simply that a vertex uses : 3 floats ( X, Y, Z ) 3 floats for normals ( nX, nY, nZ ) 1 DWord = diffuse colour 2 floats ( UV texture coordinates ) That mean 36 bytes for each vertex and it contain floats and dword ( I'll use integer for dword ) That why I need to Read/Write int and float from the same memory block.
All we have to decide is what to do with the time that is given to us.
Keep in mind that what Freddix is trying to do is make a DarkBasic clone for AmigaOS 4.x and, as a spin-off of AmosPro for the PC, the blocks of memory are very much like Amos Bank formats. You access the memory in these blocks using versions of the BASIC Peek and Poke commands.
@thread
That being said, I'd still use a union of Int32 and Float32 in case endian correction becomes an issue because the byte-swapping opcodes in the PowerPC instruction set only apply to integers. That means you can only endian-swap a float by loading it into a general-purpose register.
@freddix
Does DarkBasic have an equivalent of the AmosPro "Set Double Precision" command that affects all floats in a program? If so, you might want to make the same union an Int64 (or long long) and a Float64 (or a double) for such cases. That way you could still guarantee that the endian correction would take place properly in the C++ syntax in the backend.
@TonyW: I can't use this, it should make the coding more complex than it actually is ... and I want to use simple memory allocation not trying to create structure for each cases ... Memory block size is defined depending on the amount of vertexes used for the object to create ... Simple AllocMem and a simple SetObjectVertex( int ObjectID, int VertexID, float X, float Y, float Z ) can define a vertex. Normals are under an algorithm and UV and COLOR are defined with SetObjectVertexUV( int ObjectID, int VertexID, float UVU, float UVV )... Samurai_Crow tell you exactly why I don't use structure in that case.
@Samurai_Crow Never seen this on DarkBASIC nor DarkBASIC Pro. but it's maybe something I'll add to my "to do list" in case ;)
Thank you for these answers.
All we have to decide is what to do with the time that is given to us.