Array Descriptor (split from Wiki Improvements)

Forum for discussion about the documentation project.
Post Reply
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Array Descriptor (split from Wiki Improvements)

Post by fxm »

fxm wrote:I proposed to write an article around this subject:
fxm wrote:Another potential new article #18 ?

About:
  • How is array passed to FB procedure and what can procedure body do versus main body
I already wrote posts around this topic.
I could complete these and reword/synthesize all that in an article.

Would some people be interested in such an article?
But as only one person echoed (paul doe, favorably, but probably already knew the subject), I did not write it.
To have an article on this subject (only about what FB currently allows) does it interest someone else?
(before I delete my preliminary notes)
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wiki improvements

Post by dodicat »

There has been a complaint recently about the ability to redim a fixed size array inside a sub or function (or any scoped block for that matter)

Code: Select all



dim as integer i(5)
for n as long=0 to 5
    i(n)=n^2
    print i(n);
next
print
print

scope
    redim i(10)
    for n as long=0 to 10
    i(n)=-n^2
    print i(n);
next
print
end scope



print
for n as long=0 to 5
    print i(n);
next
print
sleep
 
Personally I think this is OK.

A method for determining whether the array pointer was on stack(fixed size) or off stack (dynamic), (without using asm) could perhaps interest some forum members.

If you have produced an article about arrays in general then it would interest many I am sure.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

dodicat wrote:There has been a complaint recently about the ability to redim a fixed size array inside a sub or function (or any scoped block for that matter)
Static arrays can't be resized, period. Some code might look like it's possible but,
we are dealing with a wrong assumption here, because:

Regarding your posted code:

the array inside the scope-block is totally independent (standalone), from
the one outside the scope-block (therefore, "ReDim" is misleading in the
context ... using "Dim" whould do, too.)

NOTE: on leaving the scope-block, everyting declared inside is destroyed!
(this is the reason, that there is no "duplicated ..." error, from compiler)
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Wiki improvements

Post by dodicat »

Yea, that was a stupid example of mine MrSwiss.
I should have used a sub for an example.

Code: Select all

sub dothis(a() as integer)
    redim preserve a(10)
    for n as long=0 to 10
   if n>5 then a(n)=-n^2
    print a(n);
next
end sub


dim as integer i(5)
for n as long=0 to 5
    i(n)=n^2
    print i(n);
next
print


dothis(i())

print

print
for n as long=lbound(i) to ubound(i)
    print i(n);
next
print
sleep
   
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

dodicat wrote:I should have used a sub for an example.
It's similar, to a scope-block, as soon as the sub is left, we're back
to square A1. (a(10) is temporary only! should IMO, be disallowed,
or at least throw a Warning/Error)
a()'s bounds checks are the originally defined ones! Even inside Sub.

Code: Select all

Sub dothis(a() as integer)
    redim preserve a(10)
    for n as long=0 to 10
        If n>5 then a(n)=-n^2
        Print a(n);
    Next
    Print : Print
    Print "a("; Str(LBound(a)); " To "; Str(UBound(a)); ")"
    print
end sub


dim as integer i(5)
for n as long=0 to 5
    i(n)=n^2
    print i(n);
next
print


dothis(i())
Print "i("; Str(LBound(i)); " To "; Str(UBound(i)); ")"

print

print
for n as long=lbound(i) to ubound(i)
    print i(n);
next
print
Sleep
I'm pretty confident, that this behaviour is very close, to a bug ...
More fun is: "commenting out" Redim Preserve a(10), doesn't change anything!
(except, special checking options, like -exx are used to compile)
Last edited by MrSwiss on May 26, 2019 13:34, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:More fun is: "commenting out" Redim Preserve a(10), doesn't change anything!
The difference is that in this case, when compiling with the -exx option, you always get an "error 6 (out of bounds array access)" execution error.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

In the array descriptor, I do not see a field to discriminate a fix-len array against a var-len array.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

Just added that comment in my post, because I know by now,
your "modus operandi", which always requires, additionals ... ;-(
(and, it's honestly, a pain in the rear, having to spell things out,
for the umpteenth time)
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

My remark was sufficient in itself. It was not necessary (and I was not asking it) to update your post.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

fxm wrote:My remark was sufficient in itself. It was not necessary (and I was not asking it) to update your post.
Your remark was written at about the same time, as my addition
(you just posted Seconds, before I did).

It's IMO, not necessary to mention -exx in every post, that's what irks me, most ...
(and, your (failing) attempt, to always be 100% correct, people are very well able
"to read between the lines", too)
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Wiki improvements

Post by speedfixer »

fxm does bring in side topics frequently, but he usually has something on his mind when he does this, and then drags it out into multiple posts. Give him time to finish his thought and see where he goes first before you jump too quick.

Personally, what is the problem?

Scope is scope and we don't need any bonus code to escape it or break it.

Declare your array common shared in main (or include to main) with 'any', redim in functions, re-assign the shared pointer, use that common shared pointer for access for a return value.
I use this with UDTs all the time.

Don't break that.

david
Last edited by speedfixer on May 26, 2019 15:54, edited 1 time in total.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:people are very well able "to read between the lines", too
If you think so, apply that to yourself as well.
speedfixer
Posts: 606
Joined: Nov 28, 2012 1:27
Location: CA, USA moving to WA, USA
Contact:

Re: Wiki improvements

Post by speedfixer »

re: MrSwiss comments

Some people don't like my posts. Not everyone is trying to be a star or gather points by making a comment that does not contribute. Should I stop?

fxm works hard to provide value. Even if I disagree with him (and he with me) he still is trying to contribute, not just make noise. Some people don't like his style. Should he stop? fxm is fxm.

My methods don't always follow someone's convention. But if I did, I wouldn't be me. I'm wrong sometimes. (Are you ever wrong?)

My 'against convention' has been successful enough for me to retire at 55, over ten years ago. I'm still thinking about buying a summer place in Italy or France.

I'll keep my method over yours, thank you.
Oh - 'between the lines' ??? Listen to yourself.

I don't know fxm. I don't know how successful he may be. But I DID learn a long time ago to be patient, and learn from successful people. His code is successful, even if I may not like his style. So, I learn from him.


YOUR method drives people AWAY from FB. THANK YOU.

david
Last edited by speedfixer on May 26, 2019 15:57, edited 2 times in total.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Wiki improvements

Post by MrSwiss »

fxm wrote:If you think so, apply that to yourself as well.
In order to do so, you'd have to write more, than single liners.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Wiki improvements

Post by fxm »

MrSwiss wrote:
fxm wrote:If you think so, apply that to yourself as well.
In order to do so, you'd have to write more, than single liners.
You misunderstood me. I did not talk about me.
I wanted to say:
Do you always try to read between the lines of user posts before answering?
Post Reply