Is it possible to put freebasic functions into C?

New to FreeBASIC? Post your questions here.
Post Reply
BristolBrick
Posts: 36
Joined: Feb 24, 2016 3:34
Location: Australia

Is it possible to put freebasic functions into C?

Post by BristolBrick »

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?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Is it possible to put freebasic functions into C?

Post by dodicat »

This works in c (win 10)

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;
} 
You can use a freebasic dll (say sleeper.bas to sleeper.dll)

Code: Select all

#cmdline "-dll"

sub _sleep(n as long) export
    sleep n
end sub

     
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).
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Is it possible to put freebasic functions into C?

Post by grindstone »

Already somewhat older, but maybe also have a look at this Winamp plugin. Winamp is written in C, the plugin in FB.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Is it possible to put freebasic functions into C?

Post by caseih »

Why couldn't you get FreeBASIC set up on your Linux machine? What problem did you encounter? What distribution?
BristolBrick
Posts: 36
Joined: Feb 24, 2016 3:34
Location: Australia

Re: Is it possible to put freebasic functions into C?

Post by BristolBrick »

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.
caseih wrote: Sep 22, 2022 13:47 Why couldn't you get FreeBASIC set up on your Linux machine? What problem did you encounter? What distribution?
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.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Is it possible to put freebasic functions into C?

Post by caseih »

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.
Post Reply