resursice arrays with 0 elements at compilation

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

resursice arrays with 0 elements at compilation

Post by PMV »

The use of complex datatypes in structures is a really great thing
(like maps and linked lists).
One of the best thing is, that we can now use them without pointers
to make recursive structures. We doesn't need to allocate memory,
we doesn't need to initialize them ... all is done by PB itself. But why
is it not the same for arrays? We have already static arrays in structures.
So when anyone knows the size of this array at compilation time, he
can use this. I use dynamic arrays, when i doesn't know what size it
will have at runtime. I think that is the normal behavior for every
programmer here. :) We could say, that from 100 cases, only 1 is
usefull to have PB initialize the array with a given size defined at compilation
time.

So, everyone would be very pleased to not have PB do that. And i
doesn't say, you should change the current behavior. There is a better
solution. An dynamic array inside a structure is only a pointer. The
elements can only be initialized, when there are some. So

Code: Select all

Structure myStruc
  Array recursiv.myStruc(0)
EndStructure
can not create any element. No endless recursion at compilation time.
It is like using maps or linked lists, as they have no element when
PB initialize them, too. :D

I doesn't know what big it is to change the compiler to allow this, but
i hope that effects only a few lines of code. At first the message
"endless recursion" should only appear, when there is no zero.
I would be glad to see this in the next feature update. :mrgreen:

MFG PMV
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: resursice arrays with 0 elements at compilation

Post by Trond »

Array(0) is an array with 1 element.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: resursice arrays with 0 elements at compilation

Post by PMV »

only untill fred has changed it :lol:
It would be easier to read, but yes ... of course it could
be -1, too ... or anything else.
Post Reply