Page 1 of 1
[Solved] Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 11:41 am
by Atlas
Hello,
I have started writing a simple kernel in FreeBASIC. And as the title says I've come to the point where
I can't work without global variables. I know it is nativly possible to use them in C but for some reason
in FreeBASIC it requires the runtime.
So to get to the point: Does anybody know how i can get globals working in FreeBASIC?
greets,
Atlas
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 1:27 pm
by linguofreak
I doubt it. BASIC, unlike C, is not really designed for low-level programming, so I doubt many people here have even bothered trying to write an OS with it. You might have better luck asking on a FreeBASIC forum.
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 1:34 pm
by Atlas
Yes but then I think few to none will no how to write
operating systems. People might know a lot about programming
on top of a "host OS", but I'm quite sure not many would have tried OS-deving yet.
Greets,
Atlas
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 1:54 pm
by AJ
Hi,
There are pointers and links on the
FreeBASIC wiki page and barebones, including a general description of what you need to get the runtime working. I'm guessing that Combuster will come in at some point and be more helpful
Cheers,
Adam
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 2:10 pm
by Atlas
I've already read and reread those pages quite often.
But im not nearly as far that i can port the complete runtime.
what im trying to do right now is setting up GDT and IDT.
I'm trying to translate
this into FreeBASIC.
(I would use C but i don't like the syntax for some reason.
I just always forget semicolons at the end of lines and that sort of thing.)
Greets,
Atlas
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 2:54 pm
by Combuster
I know it is nativly possible to use them in C but for some reason
in FreeBASIC it requires the runtime.
That is because globals might just be one of the managed types and FreeBasic drops in a constructor reference to, iirc, fb_hInit which is responsible to set the globals for the runtime before that.
At any rate, you will need a copy of the FreeBasic runtime matching the compiler version. You don't even nearly need all of it, but you should look through it to find the missing functions, then compile them along with your project. In the case of hInit, there's some platform-specific code involved so you have to provide them or you might want to start with a reduced version of that function until you can actually provide all the dependencies.
Bottom line is, you will have to write C code. At least until you're so intimately familiar with the compiler internals that you can perform that functionality in the runtime-free subset of basic.
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 3:04 pm
by Atlas
Ok I have the FB source but there are about 600 files and i haven't
got the faintest idea which files to look through for those functions.
Greets,
Atlas
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 3:06 pm
by Combuster
Learning to search would be a good start. Explorer can do it, and so can find | xargs grep.
Re: Globals in FreeBASIC?
Posted: Sat Aug 18, 2012 8:19 pm
by darkinsanity
Wait, why would you need the runtime for globals? What's wrong with "dim shared" ? If you need the same variable in more than one source file, there is also "common shared".
Also, a look at
this might help.
Re: Globals in FreeBASIC?
Posted: Sun Aug 19, 2012 2:05 am
by Atlas
Oh thanks, well at least i don't get blablabla is not declared erreors now.
Why doesn't it work with simple dim?
I'll take a look into Frost, it could help me quite alot.
and I'll also try setting up that runtime sometime.
Greets,
Atlas
Re: [Solved] Globals in FreeBASIC?
Posted: Sun Aug 19, 2012 6:07 am
by darkinsanity
Well, there is no "main" in FreeBASIC, so writing dim outside of a function is the equivalent of declaring a variable inside the main function of C, just like putting any code there is the equivalent to putting it inside main in C.
When you want a global variable in C, you just declare it outside any function, but in FreeBASIC, the compiler would think that you want to use it only outside of functions. So, in FreeBASIC, "dim shared" is necessary to tell the compiler that you need a variable that is not only usable outside of functions (this is the equivalent to "main" in C) but also inside.
I hope it's understandable because I find it a bit hard to explain.
Re: [Solved] Globals in FreeBASIC?
Posted: Sun Aug 19, 2012 6:36 am
by Atlas
Yes it's perfectly understandable.
Greets,
Atlas