March 28, 2024, 05:41:47 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


A little bug maybe?

Started by Ficko, May 30, 2007, 02:51:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ficko

This little bug had given me some hard time may Paul wanna look into it. :-\

TYPE MyType
   DEF My32:INT
   DEF My64:UINT64
ENDTYPE

DEF Ints:MyType
Ints.My32 = 0x10101010
Ints.My64 = 77309411327q:'0x11FFFFFFFF

Dump of â€Ã...“Intsâ€Ã,:

0040F010  10 10 10 10 00 00 00 00      ....
0040F018  FF FF FF FF 11 00 00 00  ÃÆ'Ã,¿ÃÆ'Ã,¿ÃÆ'Ã,¿ÃÆ'Ã,¿ ...
0040F020  00 00 00 00 00 00 00 00  ........
0040F028  00 00 85 00 00 00 00 00  ..â€Ã,¦.....
0040F030  00 00 00 00 00 00 00 00  ........
0040F038  00 00 :o

You can see that ESI got increased with 8 despite â€Ã...“My32â€Ã, is only an INT.

I had a TYPE def with 3 INTs and want to combine LO+HIGH to one UINT64 like above but it didn’t work so I had to dig into deeper what’s going on.

Ionic Wind Support Team

Read the users guide about structure packing. 

TYPE MyType, 1
   DEF My32:INT
   DEF My64:UINT64
ENDTYPE

Would specify one byte packing for example.  The default is 8, which is a defacto standard with current languages. 

Here is a reasonable reference to it:

http://en.wikipedia.org/wiki/Data_structure_alignment

Paul.
Ionic Wind Support Team

Ficko

May 30, 2007, 03:09:59 PM #2 Last Edit: May 30, 2007, 03:13:37 PM by Ficko
I didn't know you can do that "TYPE MyType, 1" :o  in EBasic!
I must missed that in the manual !

Sorry!

So I assumed 4 byte alignment is the standard in Ebasic. -Hoops!- :-[

But thanks for clarifying it! ;D

Ionic Wind Support Team

Actually the packing value default is 8.  Which is why I gave you the link so you can better understand what it does.  Since you're using an INT64, and it is 8 bytes in size, the compiler inserts the four NULL bytes to make sure that the INT64 is properly aligned in memory.  If you used two INT's then there would be no pad bytes inserted.

This statement from ANSI C describes it a little better:

Quote
ANSI 3.5.2.1 The padding and alignment of members of structures and whether a bit field can straddle a storage-unit boundary

Structure members are stored sequentially in the order in which they are declared: the first member has the lowest memory address and the last member the highest.

Every data object has an alignment-requirement. The alignment-requirement for all data except structures, unions, and arrays is either the size of the object or the current packing size, whichever is less. For structures, unions, and arrays, the alignment-requirement is the largest alignment-requirement of its members. Every object is allocated an offset so that

offset % alignment-requirement == 0

Adjacent bit fields are packed into the same 1-, 2-, or 4-byte allocation unit if the integral types are the same size and if the next bit field fits into the current allocation unit without crossing the boundary imposed by the common alignment requirements of the bit fields.

The "the size of the object or the current packing size, whichever is less"  line is what confuses most people.  Consider a UDT with a CHAR and an INT

TYPE mytype
CHAR c
INT i
ENDTYPE

The size of that UDT is 8 bytes.  The packing value isn't used since it is greater than the size of any of the elements.  The alignment requirement of 'i' is 4 so the compiler inserts three null bytes after the character to ensure that 'i' gets aligned on a 4 byte boundry.

TYPE mytype,2
CHAR c
INT i
ENDTYPE

The size of that UDT is 6 bytes.  Since the packing value is less than the alignment requirement of an INT it gets used instead.  So one NULL padding byte is inserted after the CHAR to align the 'i' on a WORD (2 byte) boundry.

EBasic and Aurora follow the ANSI specs so you can interface with the C library, Windows API, etc.   Without too much difficulty or having to add padding manually to make it work. 

Paul.
Ionic Wind Support Team

Ficko

May 31, 2007, 02:20:14 AM #4 Last Edit: May 31, 2007, 05:56:49 AM by Ficko
Thanks Paul!

It is nice to having you back! :D

I would lie to say I thoroughly got everything you wrote above  but I will dissect your writing and I do understood the general concept of it. ;)

I have an other question to the debugging capabilities of EB.

May I missing there something too but to me it behaves sometimes kind of strange like skipping loops, it’s getting out of single step mode and continue the program without my permission. >:( Etc.
It is how do you intend it to work?

Can I execute single step assembler code in the disass.-screen or it is not possible?

Ficko

I still playing with the â€Ã...¾Typesâ€Ã...“ and the first time ever I managed to generate an â€Ã...¾INTEGER_DIV_BY_ZEROâ€Ã...“ exception by just compiling this little freak here: ;D

DEF DinArray AS Pointer
TYPE DinString
   Array[5]:String   
ENDTYPE
DinArray = new(DinString,10)

Do I get expelled from the forum now? :D

Ionic Wind Support Team

You forgot the DEF

DEF DinArray AS Pointer
TYPE DinString
   DEF Array[5]:String   
ENDTYPE
DinArray = new(DinString,10)

or

DEF DinArray AS Pointer
TYPE DinString
   STRING Array[5]   
ENDTYPE
DinArray = new(DinString,10)

Would be fine.
Ionic Wind Support Team