[Implemented] Structure Enhancement Request

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

[Implemented] Structure Enhancement Request

Post by akj »

Could structures please be enhanced to use a boundary-alignment type, with the new syntax:

Code: Select all

Structure[.type>] <name> [Extends <name>]
Examples:
Structure.Q mystruct would start on at least a 64-bit boundary
Structure.L mystruct would start on at least a 32-bit boundary
Structure.I mystruct would start on at least a 64-bit boundary on 64-bit CPUs and at least a 32-bit boundary otherwise.

There would be an additional feature: the end of the structure would automatically be padded with nulls so that it also had [at least] the same boundary alignment as the start of the structure.

Thus

Code: Select all

Structure.q mystruct
  length.w
  height.w
  depth.a
endStructure
would start on [at least] a 64-bit boundary and be padded at the end with 24 bits to ensure that also lay on [at least] a 64-bit boundary.

The absence of a <type> would default to the current PB4.40 boundaries and if the Extends keyword was present, <type> would be ignored for the start of the structure, but honoured for the end of the structure.
Last edited by akj on Fri Sep 18, 2009 12:46 pm, edited 1 time in total.
Anthony Jordan
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Structure Enhancement Request

Post by Trond »

What would be the purpose of this?
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Structure Enhancement Request

Post by Demivec »

akj wrote:Could structures please be enhanced to use a boundary-alignment type, with the new syntax:

Code: Select all

Structure[.type>] <name> [Extends <name>]
Examples:
Structure.Q mystruct would start on at least a 64-bit boundary
Structure.L mystruct would start on at least a 32-bit boundary
Structure.I mystruct would start on at least a 64-bit boundary on 64-bit CPUs and at least a 32-bit boundary otherwise.
This portion of the request would be ineffective because the structure defines the access to data, not the placement of data. For example, all structures start at offset zero, thus they are already boundary aligned. It's up to the program to determine where the structure starts.

In other words, if you defined your nice 64-bit boundary aligned structure FFIRST definition what would happen if this code was used *ptr.FFIRST = 11. How would the structure definition help you at all with your boundary alignments? This is another way of identifying it as a coding problem, and not a language problem.
akj wrote:There would be an additional feature: the end of the structure would automatically be padded with nulls so that it also had [at least] the same boundary alignment as the start of the structure.

Thus

Code: Select all

Structure.q mystruct
  length.w
  height.w
  depth.a
endStructure
would start on [at least] a 64-bit boundary and be padded at the end with 24 bits to ensure that also lay on [at least] a 64-bit boundary.

The absence of a <type> would default to the current PB4.40 boundaries and if the Extends keyword was present, <type> would be ignored for the start of the structure, but honoured for the end of the structure.
This portion of the request (about ending boundaries) is simply not needed as well as being ineffective (see the first example using FFIRST). If padding is needed, then add the padding.

Code: Select all

Structure mystruct ;.q
  length.w   ;2 bytes
  height.w   ;2 bytes
  depth.a    ;1 byte
  pad.b[59]  ;59 bytes
endStructure
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Structure Enhancement Request

Post by Fred »

In fact many API structures needs corrects 4/8 bytes alignment on 32 bits and even more on 64 bits. We wanted to add some facility for this as we spend quite some time to do it right in the residents. Wait'n'see !
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Re: Structure Enhancement Request

Post by akj »

@Fred:

Thank you. That is most encouraging. So perhaps something will get implemented.
Anthony Jordan
Post Reply