Static arrays, program stack, and possible ambiguity in the manual

New to FreeBASIC? Post your questions here.
grausvic
Posts: 4
Joined: Jun 07, 2019 10:34

Static arrays, program stack, and possible ambiguity in the manual

Postby grausvic » Jun 13, 2019 9:40

I don't know how to report a possible ambiguity in the manual, perhaps this post will do, or perhaps I'm wrong at all, I'm a beginner .

In the page titled "Fixed-length arrays" of the online manual says "Fixed-length arrays with automatic storage have their elements allocated on the program stack".
Instead, in the page "Dim" (in June-2019) says "If the values used with Dim to declare the dimensions of an array are all constants, the array will be created Static" [so it won't consume the program stack].
Isn't this ambigous?

On the other hand, in the same page "Dim", on the second box or example, shouldn't X,Y,D be of the same type (whether single or double)?
fxm
Posts: 9076
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Static arrays, program stack, and possible ambiguity in the manual

Postby fxm » Jun 13, 2019 12:47

We are often talking about static arrays as opposed to dynamic arrays, but in this precise case "static" means "fixed-size" et "dynamic" means "variable-size" (its becomes from the old QB metacommands: "'$Static" and "'$Dynamic", or "Option Static" and "Option Dynamic").
No relation to the declaration "STATIC [SHARED] variable AS ...".
(I will clarify the "Dim" documentation page)

In the second example of the DIM documentation page, the comment:
'' I and J are INTEGERs
'' X and Y are SINGLEs
'' T$ is STRING
'' D is DOUBLE
should be placed after:
Dim I, J, X, Y, T$, D As Double
in order to be better coherent (I will update the page).

Remark:
In -lang qb, the INTEGER data-type is 16-bit (referenced as SHORT inside the compiler).

In the 'Dim I, J, X, Y, T$, D As Double' declaration, Double is applied on D only. The other variables are declared without "As", so their implicit types are used.
Note: At opposite, for 'Dim As Double d1, d2, d3', the Double type is applied on all variables.
fxm
Posts: 9076
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Static arrays, program stack, and possible ambiguity in the manual

Postby fxm » Jun 14, 2019 14:30

Updates (of 'Dim' documentation page) done:
KeyPgDim → fxm [Reformatted second example, between code and comment places]
KeyPgDim → fxm [Clarified the meaning of 'Static array' when used to say 'of fixed length', not to be confused with 'Static storage' for data.]
grausvic
Posts: 4
Joined: Jun 07, 2019 10:34

Re: Static arrays, program stack, and possible ambiguity in the manual

Postby grausvic » Jun 15, 2019 10:21

Now I see clearly the different meanings of Static, many thanks.

And, oh my God! Now I remember why I've never used "AS DOUBLE", "AS LONG", etc, at the end of a DIM: it always misled me!

So a reminder for beginners: DIM AS DOUBLE X,Y,D applies to all of them, DIM X,Y,D AS DOUBLE just applies DOUBLE to D.
fxm
Posts: 9076
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Static arrays, program stack, and possible ambiguity in the manual

Postby fxm » Jun 15, 2019 11:14

grausvic wrote: So a reminder for beginners: DIM AS DOUBLE X,Y,D applies to all of them, DIM X,Y,D AS DOUBLE just applies DOUBLE to D.

Referring to the second declaration ('DIM X, Y, D AS DOUBLE'), the default types (for X and Y) are only valid in -lang deprecated or fblite or qb.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 13 guests