Page 1 of 1
Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 9:19 pm
by c4s
Maybe I missed something obvious that dismisses my feature request but I don't see why Declare only works for procedures. I think it's equally important for structures, arrays, lists etc.
Code: Select all
Structure AA
AA.a
EndStructure
Structure AABB
v1.AA
v2.BB
EndStructure
Structure BB
BB.b
EndStructure
Re: Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 9:25 pm
by STARGÅTE
Why?
Procedures can call each other, structures not!
So why?
Use this, where is the problem?
Code: Select all
Structure AA
AA.a
EndStructure
Structure BB
BB.b
EndStructure
Structure AABB
v1.AA
v2.BB
EndStructure
Re: Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 9:48 pm
by skywalk
STARGÅTE wrote:Why?
Procedures can call each other, structures not!
umm, ts-soft shows otherwise
http://www.purebasic.fr/english/viewtop ... 25#p344825
Re: Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 9:58 pm
by c4s
Damnit why not? Why do we have Declare anyway? It makes coding easier!
I came across this when trying to seperate my main code file into several ones. Now I have this issue that I declare some structures in an include but want to define it in the main code file before including it because there are also variables used in the seperate file that are defined before it and so on... you don't have to understand the logic I'm trying to explain. It's just that declaring structures etc. could be handy in this case and I don't see a reason why it isn't possible.
When things are getting larger you want to have a certain code structure... In my small example I don't want reorder it because I want it like that, you know?
Re: Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 10:34 pm
by STARGÅTE
Damnit why not? Why do we have Declare anyway? It makes coding easier!
No!, Declare for procedures make it run!
Struktur never locks like:
Code: Select all
Structure AA
A.BB
EndStructure
Structure BB
B.AA
EndStructure
Procedure can it, so here we need a Declare!
PS: for structures in PB a use my extension *.pbh so i declare all structures before
i think it is not
easier to write some like:
Code: Select all
DeclareStructure BB
Structure AA
A.BB
EndStructure
Structure BB
B.i
EndStructure
Re: Declare for Arrays, Lists, Variables, Structures
Posted: Thu Jun 16, 2011 10:47 pm
by luis
To answer your question: "Why do we have Declare anyway?"
It's to make code possible, not easier unfortunately.
Mutually recursive code: how can you write that without declares with a single pass compiler ?
Code: Select all
Declare a()
Declare b()
Procedure a()
Debug "a"
If Random(1)
b()
EndIf
EndProcedure
Procedure b()
Debug "b"
If Random(1)
a()
EndIf
EndProcedure
a()
The same it's not needed for data, afaik.
Anyway, even assuming they can be useful, I shudder at the idea of maintain declares for procedures AND linked list, structures, arrays. Having redundant declarations in my code it's not something I'm looking forward to, but for procedures this is a needed evil. Well, just an opinion

Re: Declare for Arrays, Lists, Variables, Structures
Posted: Fri Jun 17, 2011 4:14 am
by Demivec
c4s wrote:Maybe I missed something obvious that dismisses my feature request but I don't see why Declare only works for procedures. I think it's equally important for structures, arrays, lists etc.
For structures it can be done via pointers. It can cause some headaches, but it is how it can currently be accomplished.
Code: Select all
Structure AABB
*v1.AA
*v2.BB
EndStructure
Structure AA
AA.a
EndStructure
Structure BB
BB.b
EndStructure