Page 1 of 1

[Implemented] Structure Enhancement Request

Posted: Fri Sep 18, 2009 12:12 pm
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.

Re: Structure Enhancement Request

Posted: Fri Sep 18, 2009 12:15 pm
by Trond
What would be the purpose of this?

Re: Structure Enhancement Request

Posted: Fri Sep 18, 2009 6:40 pm
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

Re: Structure Enhancement Request

Posted: Sat Sep 19, 2009 10:53 am
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 !

Re: Structure Enhancement Request

Posted: Sat Sep 19, 2009 5:18 pm
by akj
@Fred:

Thank you. That is most encouraging. So perhaps something will get implemented.