Redimensioning structures? Why?

Discussions related to database technologies, file handling, directories and storage
Edja
Posts: 37
Joined: Tue 03 Apr 2018, 12:07

Redimensioning structures? Why?

Post by Edja »

I was checking the manual to better understand how to work with structures. Under keyword "DIM" I've read
you can repeat a structure declaration so long as the format is identical to that specified when it was first declared. In this case the contents of the structure remain unchanged: they are not initialised.
Why would I ever redimension a structure if this doesn' t change anything ? A programming technique I'm not familiar with perhaps ?
Edja

RichardRussell
Posts: 533
Joined: Tue 15 Oct 2019, 09:10

Re: Redimensioning structures? Why?

Post by RichardRussell »

Edja wrote:
Sat 15 Aug 2020, 12:05
Why would I ever redimension a structure if this doesn' t change anything ?
The most likely reason is a PRIVATE structure. Consider this procedure:

Code: Select all

      DEF PROCtest
      PRIVATE struct{}
      DIM struct{member1, member2}
      struct.member1 += 1
      PRINT struct.member1
      ENDPROC
Since the structure is declared as PRIVATE its contents must remain unchanged from one call of the procedure to the next, that's the definition of PRIVATE. But necessarily the structure is declared within the procedure, since that defines its scope, so if the declaration were to initialise the contents of the structure the PRIVATE would be ineffective. You would end up with it behaving like a LOCAL structure instead.

There are other situations in which applying the principles of Information Hiding or Encapsulation you might find it desirable to declare even a global structure multiple times rather than just once, to hide its declaration from view. The dlglib library does that a lot, I think.
If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.

Edja
Posts: 37
Joined: Tue 03 Apr 2018, 12:07

Re: Redimensioning structures? Why?

Post by Edja »

OK, understood. Thank you!
I'll have a look too at the dlglib code

Edja