[Solved] Globals in FreeBASIC?

Programming, for all ages and all languages.
Post Reply
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

[Solved] Globals in FreeBASIC?

Post 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
Last edited by Atlas on Sun Aug 19, 2012 2:06 am, edited 1 time in total.
Cogito ergo sum!
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: Globals in FreeBASIC?

Post 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.
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

Re: Globals in FreeBASIC?

Post 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
Cogito ergo sum!
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Globals in FreeBASIC?

Post 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
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

Re: Globals in FreeBASIC?

Post 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
Cogito ergo sum!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Globals in FreeBASIC?

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

Re: Globals in FreeBASIC?

Post 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
Cogito ergo sum!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Globals in FreeBASIC?

Post by Combuster »

Learning to search would be a good start. Explorer can do it, and so can find | xargs grep.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: Globals in FreeBASIC?

Post 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.
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

Re: Globals in FreeBASIC?

Post 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
Cogito ergo sum!
User avatar
darkinsanity
Member
Member
Posts: 45
Joined: Wed Sep 17, 2008 3:59 am
Location: Germany

Re: [Solved] Globals in FreeBASIC?

Post 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. ;)
Atlas
Posts: 6
Joined: Sat Aug 18, 2012 11:24 am
Location: 127.0.0.1
Contact:

Re: [Solved] Globals in FreeBASIC?

Post by Atlas »

Yes it's perfectly understandable. :lol:

Greets,
Atlas
Cogito ergo sum!
Post Reply