I couldn't get freebasic set up on my linux machine, so I am learning the basics of C. I made a loop that prints nonsense, but I wanted to slow it down. It's always been so simple in QBasic/Freebasic: sleep(x), in milliseconds. I've tried importing about 5 different libraries and not one has something like it. Sleep(x) is either in seconds (way too slow since it only accepts integers) or I got some error, or I found one in microseconds, but it's a deprecated function in unistd.h, which I think only works on Linux anyway.
I know C code can be loaded into freebasic (though I've never done it), is there a way to do the reverse?
Is it possible to put freebasic functions into C?
-
- Posts: 36
- Joined: Feb 24, 2016 3:34
- Location: Australia
Re: Is it possible to put freebasic functions into C?
This works in c (win 10)
You can use a freebasic dll (say sleeper.bas to sleeper.dll)
then call the dll at compile time in c
void _SLEEP(int n);
(it has to be a dll because you are using fb_sleep, so a static lib won't do).
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
printf("Program will sleep for 10 milisecond .\n");
sleep(0.01);
printf("This line will be executed after 10 milisecond.\n");
system("pause");
return 0;
}
Code: Select all
#cmdline "-dll"
sub _sleep(n as long) export
sleep n
end sub
void _SLEEP(int n);
(it has to be a dll because you are using fb_sleep, so a static lib won't do).
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Is it possible to put freebasic functions into C?
Already somewhat older, but maybe also have a look at this Winamp plugin. Winamp is written in C, the plugin in FB.
Re: Is it possible to put freebasic functions into C?
Why couldn't you get FreeBASIC set up on your Linux machine? What problem did you encounter? What distribution?
-
- Posts: 36
- Joined: Feb 24, 2016 3:34
- Location: Australia
Re: Is it possible to put freebasic functions into C?
Thanks for the advice, using dll files looks interesting. If I understand it right, I could use any language that could compile to dlls and stuff those functions into any other, seems very useful.
Couldn't figure out how to get the compiler working, either by hooking it up to an IDE or manually through the terminal. It was easier to keep using my windows laptop for FB instead. Linux Mint 19, probably just completely my fault. Anyway, still using FB, I think it will stay my favourite over C. C seems to have similar functionality, slightly faster runtime but chucks headaches at me a little more often. Also, GCC's error messages aren't as helpful as fbc's. Still leagues better than python's.
Re: Is it possible to put freebasic functions into C?
Was it the old libtinfo.so problem? If so, I believe "sudo apt install libtinfo5" is all that's required to install that dependency. With libtinfo5, the package you download from this web site will run just fine Mint 19.
A tip regarding gcc errors is that when a syntax error occurs, the root problem is likely a bit previous to the point where the compiler choked. For example things like missing parenthesis, missing braces, etc.
A tip regarding gcc errors is that when a syntax error occurs, the root problem is likely a bit previous to the point where the compiler choked. For example things like missing parenthesis, missing braces, etc.