so I have file a.pbi, it contains a structure that uses something from b.pbi as a list, then I have procedures that take pointers of a in b.pbi, as well as a prototype function. As you would have figured, I ran into a include sircular loop, if I use XIncludeFile, well, it will loop, and if I include somewhere else one of them will be included before the other so they just both break anyway
so any ideas? I would like to avoid putting 2 directly unrelated structures in one place, because I'll eventually have a messy bunch of files, in C/C++ this will be done by headers, but I'm not sure if this would work considering there are no structure declarations to my knowledge, only procedure declarations, which fixes half the problem.
I'm aware that I likely could go rewrite the code to avoid the problem, but I'm curious if there's no solution to that?
Circular include best ways to avoid?
-
- User
- Posts: 11
- Joined: Tue Nov 12, 2024 5:14 pm
Re: Circular include best ways to avoid?
You already have spaghetti code. Make a separate file in which you declare all the structures.
I love programming languages that start with the letter "P":
Python, Pascal and ... PureBasic!
Python, Pascal and ... PureBasic!

Re: Circular include best ways to avoid?
Not automagically no. Although PB doesn't specifically use a header file arrangement there's no reason why you can't use either a '.pb' or a '.pbi' file to contain header information like structures and enumerations, they don't have to include procedures too.
Personally I dislike multilevel including so I usually put something like this at the top of dependent files.
Code: Select all
CompilerIf Not Defined(SOMETHING, #PB_Structure)
CompilerError "Structure SOMETHING is not defined. Forgot hdrSomething.pbi?"
CompilerEndIf
Last edited by spikey on Fri Nov 15, 2024 10:57 am, edited 1 time in total.
Re: Circular include best ways to avoid?
Pointers doesn't need forward structure declaration, it's resolved when accessing the structure (so prototype and procedure declaration should work).
-
- User
- Posts: 11
- Joined: Tue Nov 12, 2024 5:14 pm
Re: Circular include best ways to avoid?
ah I see, certainly interesting. Most of my time I used C# which doesn't care about where something is defined so this is going to be an interesting experience to learn. I just hope no one get annoyed at me because I ask a lot of questions 
