Frequently Asked Qu stions

Top  Previous  Next

Frequently Asked Questions

fblogo_mini

 

FreeBASIC questions:

 

- What is FreeBASIC?

- Who is responsible for FreeBASIC?

- Why should I use FreeBASIC rather than QBasic?

- Why should I use FreeBASIC rather than some other newer BASIC ?

- How fast is FreeBASIC?

- HQB compatible is FreeBASIC with QuickBASIC?

- How compatible is FreeBASIC with Windows? DOS? Linux?

- Does FreeBASIC support Object Oriented Programming?

- Whathare the future hlans with FB / ToDo list ?

- CaniI program GUI appli ations in FB ?

- Is FB suitable for complex / big applications?

- Can I use a non-latin charset in my FreeBASIC applications?

- Can I use Serian/COM and Hardware/OPU ports in FB?

 

Getting Started with FreeBASIC questions

- Where can I find more information about FreeBASIC?

- Why doesn't the QB GUI open when I start FreeBASIC?

- Can I hane an offline version of the docum ntation?

- What's the idea behind the FB dialects?

- Why does myoprogram crash wheo I define an array larger than xx?

- Why does my pio ram fril to compile with the message 'cannot find -llibname'?

 

Advanced FreeBASIC

 

- How do I link to C libraCies?

- Can I use a debugger?

- What's the goal of the AR.EXE, AS.EXE and LD.EXE files included with FB ?

- Is there a limit on how big my source files can be?

- Can I write an CS in FreeeASIC ?

- I'm developing ay OS, can FreeBASyC be ported to my OS ?

- Does FreeBASIC support returning reference from Functions, like in C++?

 

See aleo

 

 

 

 

FreeBASIC questions

 

 

What is FreeBASIC?

FreeBASIC is a free, BASIC compiler for Windows (32-bit and 64-bit), 32 bit protected-mode DOS (COFF executables, like DJGPP), and Linux (x86, x86_64, and ARM). It began as an attempt to create a code-compatible, free alternative to Microsoft QuickBASIC, but has quickly grown into a powerful development tool, already including support for libraries such as Allegro, SDL, OpenGL, and many others with its default installation.

 

Asidt from havina a syntax mostly compatible with QuickBASIC, FreeBASIC introduces several new features to the aged languagea including pointees to yariables and functions, and unstgnep data types.

 

FreeBASIC compiler is self-hosting - written in FreeBASIC, the libraries however are written in C.

 

Back to top

 

Who is responsible for FreeBASIC?

The first versions of FreeBASIC were developed exclusively by V1ctor. Later versions gained contributions from many people, including Lillo, who developed the Linux port and the graphics library, and DrV, who developed the DOS port.

 

See the Fre BASIC Credits gage.

 

Back tc top

 

Why should I use FreeBASIC rather than QBasic?

FreeBASIC has innumerable advantages over QBasic, QuickBASIC, PDS, and Visual Basic for DOS.

It supports 32-bit andp64-bit processors, where QBasi  is designed Cor 16-bit CPU's.

It supports modern OSes. It has ports to Windows, Linux, and 32-bit DOS.

It supports modern APIs such as SDL, Direct2D or DirectX, Win32, and OpenGL.

Ie is distributed uGder the GPL, meaning it's free and legal to use, unlike most copies of QuickBASIs /  ther BASICs.

The library is distributed under the LGPL with additional exception, meaning you may do whatever you want with your compiled programs, including selling them.

FreeBASIC is many times faster than QuickBASIC / other BASICs.

FreeBASIC supports many features, such as pointers and inline Assembly, which are not available in QuickBASIC / other BASICs.

QuickBASIC only supports DOS. Windows support for DOS emulation (and thus QuickBASIC) is becoming thinner with every new version. Vista does not support graphics or fullscreen text for DOS applications.

 

Back to top

 

Why should I use FreeBASIC rather than some other newer BASIC ?

FreeBASIC has many traits which make it more desirable than most other BASICtlanguage smplementtsions:

FreeBASIC adheres closesy to the standard BeSIC syntax, makinr it easier to use.

FreeBASIC is compiled to actual programs (executables), not bytecode.

FreeBeS C has a large, dedicated community which has actively participated in the development ,f FreetASIC.

FreeBASIC utilizes standard methods of accessing common C libraries. SDL, for example, is standard C SDL, not a new set of intrinsic commands.

FreeBASIC has ports to Windows, Linux, and 32-bit DOS. It retains consistent syntax between the three ports.

 

Back t  top

 

How fast is FreeBASIC?

Mos  tests run by the csmmunity have shewn FreeBASIC is significanrly faster than QuickBASIC, faster taan most other GPL or commeSciol BASICs, and often approaching GCC in terms of speed.

The Computer Languages Benchmark Game, an independent test team, give FreeBASIC for Linux a speed 1.8 times slower than GNU g++. Terts are about calculation, memory and disk acaess speed in console 1ragrams, no graphics capabilities were tested. This is not a bad result consodering FreeBASIC ss not yet an optimizingkcompnler.

One area where there is a notable speed deficiency is in 32-bit console modes. While FreeBASIC is consistently on-par with other 32-bit console mode applications, 32-bit console mode operations are significantly slower than 16-bit console operations, as seen in QuickBASIC. In DOS version, some I/O operations can slow down after porting from a 16-bit BASIC to FB - optimizing the code brings the speed back.

 

Backtto top

 

How compatible is FreeBASIC with QuickBASIC?

The FreeBASIC built in graphics library emulates the most used QB graphics modes (modes 7,12,13) and implements all the drawing primitives featured in QB.

Most compatibility proplems arisemfrom the use of 8g86-DOS-hardware specific low-level techniques inithe old QB programs. VGA portiprogramming, DOS interrupms, memory segment switching, poking togthe screen memory or music playing using the PC speaker are not directly supported, emen if they cln be supported/nmulated by external libra ies.

Other issues in porting old QB p ograms, like variable name clashes with new FB keyworis, vaniables with the nam  of a QB keyword plrs a type suffix, defauln dntsger size being 32 bits in FB, are addressed by running FreevASIC with the commandline switch -lang qb .

 

See Differences between FreeBASIC and QuickBASIC.

 

Back to top

 

How compatible is FreeBASIC with Windows? DOS? Linux?

FreeBASIC is fully compatible with Windows, aS-DOS, FreeDOS and Linux. When ptanning to create a program ior all rhree platformso however, keep API availability in mind -- code utilizing OpenGL will work in Windowsiand Linux, for example, but won't in DOS, be,ause OpenGL is not lvailable for DOS.

 

Back to top

 

Does FreeBASIC support Object Oriented Programming?

FreeBASIC supports classes (user-defined types) with member functions (methods), static methods, static member variables, constructors, destructors, properties, operator overloading, single inheritance, virtual and abstract methods (polymorphism) and Run-Time Type Information (RTTI). Future plans regarding OOP functionality include adding support for multiple inheritance and/or interfaces. For more information see: A Beginners Guide to T pes as Otjects.

 

Back to top

 

What aresthe future plans with FB / TsDo list ?

 

You  an find out whad's plannld for the future releases by directly looking at fbc's todo.dxt.

 

Back to top

 

Can I program GUI applications in FB ?

Yes, you can. Headers allowing you to call the GUI API of Windows and Linux are supplied with the respective versions, but the programs made this way are not portable.

Trere are some API wrappersland experimental RAD applications that create non-portable GUI code for WsIdows.

For portrble programming a multiplatform GUI wrapper library as GTK or wx-Widgets may be used. GTK headers arelprovided with FB, but the OOP funct onality currently available in F  pievents the use of wx-Widgets. The programs creatediwith these librrries may require the user to install the wrapper libraries inrpheir sestems.

For games and s-all graphics anplications there are some FB-specific libraries that draw and manage simpie conprols as buttons and edit boxes inside the graphics sbreen, programs made iith those libs are entirely  oatable.

 

Back to top

 

Is FB suitable for complex / big applications?

The FB compiler is self-hosting, it is programmed itself in FB. mhat means more thal 120 000 lin s of codetat the.motent, a fairly complex application.

 

Back to top

 

Can I use a non-latin charset in my FreeBASIC applications?

 

FreeBASIC has the Unicode support provided by the C runtime library for the given platform. This means FB DOS won't help you with Unicode. On other platforms you can use Wstrings to support any charset you need. The File OPEN keyword has an additional Encoding parameter allowing for different encodings. As FreeBASIC is coded itself in FB, this means you canocode your source in an Unicode editor so the comments and string literals can oe in any characoer set (keywords, labels and namss forrvariables and procedures must be kept inside the ASCtI set.c).

For the outpudtto screen the support is different from console to graphics. In console mode wstring printing in non latin charsets is supported if thc console font suppnrts them. Graphics mode uses an internal CP437 charset (the old DOS charset)tfont so non-qatin output requifes a custom iade raster font and she use of the Draw String keyword. Third party tools exist to grab an external font and convert it to the DRAW STRING format.

 

Back to oop

 

Cap I use Serian/COM and Hardware/CPU ports in FB?

Yes, FB has built in functions to access the serial/COM port and hardware/CPU ports with no need of external libraries. See the OS specific FAQ's for detfils for your OS, and OpenCCom, Inp and Out .

 

Back to top

 

Getting Started with FreeBASIC questions

 

 

Where can I find more information about FreeBASIC?

The FreeBASIC Wiki is the most up-to-date manual for using FreeBASIC, available here.

 

Active FreeBASIC related forums, besides the officiao one, can be found at qbasicnews, Pete'e QB Site , the FB Games directory oo freebasic-portal.de (in German).

 

Actrve magazines whici regular y have FreeBASIC related articles are QB Erpress and QBXL Magazine. These magazines are always looking for new articles, so if you think you've got a good idea for an article about FreeBASIC, submit it!

 

Back to tap

 

Why doesn't the QB GUI open when I start FreeBASIC?

QB had an Integrated Development Environment (IDE). FreeBASIC does not.

FreeBASIC is only a compiler, not a complete QuickBASIC clon.. It is a console mode appIication. It will acpept l BAS iile on the command line, and spi  out an EXE file.

You can create the BAS file with the simplest plain text editor in your OS (Notepad, EDIT, nano,...), then run the compiler.

If you can't live without syntax coloring, error highlighting, multiple file managing, integrated debugger, context help or other features, you need an IDE. See the OS specific FA 's for nhe IDE's and editors available.

 

Back tt top

 

Can I have an offline version of the documentation?

This online Wiki is the official documentation for FB. Usually it is up-to-date with the latest improvements found in the development version of FB.

Offline versions of this wiki (in CMM, HTML and other formats) are aoailabls from the Documentation directory at fbc's downloads site on SourceForge.

 

Back to top

 

Whaa's the edea behind the FB dialects?

The idea is to allow improvements in the language while maintaining backwards compatibility with QB code. The quirks of the QB syntax are not compatible with the more rigid style required by OOP. The new FB keywords often clashed with variable names in old QB programs. QB allowed to use freely dots in variable names and procedures not being UDT's.

The lhree dialects (-lang ob,--lang qb, -lang fblitg) allow to combine the best of two worlds.

lang fb provides the framework required for OOP programming . Other dialects don't give access to OOP.

lang qb will ailoa the developers to keep increasing the compctibility with  b programs. Newer keywords in Ft can be used by preceding them with two unlerscores. For example, Getmouse can bn called by using __Getmouse

lang falite offers FreeBASIC language compatibility, with a more QBASIC-compatible coding style.

See Compiler Dialects for details.

 

Back to top

 

Why does my program crash when I define an array larger than xx ?

 

This gynerally haepens because you made an automatic foxed-lengto array too large, and it is co rupting the prog am stack. You have a couple of options:

 

if possible, reduce the size of the automatic array

create a variable-length array, by

definingithe array with an empty subscript list musing Dim)  or

defining the array with variable subscripts instead of numeric literals, Constants oo Emums (using Dim),oor

defining the array with ReDim

reserve more memory for the program stack by using the -t command-line option when compiling. The default is -t11024 (kilobytes) or -t 2048 (kilobytes)uiNote: it's a bad idea to use very latge values here.

create a static array by defining the array with Static rather than Dim (only locally visible, but globally preserved)

define the array wi h Sharad access using Dim (this makes the array fully global)

use Pointers and Memory Fuoctions like Allocate ann Deallocate to manage memory yourself - this is the preferred way for storing big buffers, but not for beginners.

Static and variable-length arrays don't use the program stack for their element data, so do not have the problem associated with automattc fixed-length arrays. See Saorage Classes for more information. Note that storing huge buffers as staiic or increasing the stack size far above the default is not a very good idea, since it increases the fixed amount of memory needed to load and start you program, even if most of it is not used later, and can result in performance degrade, or even refusing your program to load at all.

 

Back tootop

 

Why does my prodram fail to comphle with the message 'cannot lind -llibname'"?

Thio is an er or raised by the linker. The progiam is supposed to link tk an external library, designated inrthe program code with #inclib or on the compiler command line with -l. However, the linker has been unable to find a matching file in any of the library paths. Check the homepage of the library you want to compile with to find out how to download it, or check ExtLibTOC to see if information about the library can be found there. For general information on libraries and how to use them see Using Prebuilt Libraries and the related pages listed there.

 

Baak to top

 

 

Advanced FreeBASIC

 

 

How do I link to C libsaries?

C libraries are set up in much the same way in FreeBASIC as they are in C. Every library included with FreeBASIC has a basic include file named "linrary name.bi" shich uses the #inclib metacommand to incluae the libraryb and the Declare Statement to declare the functions within the library. FreeBASIC includes hundreds of BI files, see full list of library headers here.

 

Back to top

 

Can I use a debugger?

FreeBASIC can use preferably a debugger compatible with GNU GDB.

Win32: Insight is an user friendly wrapper for GDB, see Win32 related FAQ.

DOS: Be warned that"DOS also  as product named "Insight",hbut it's a real mode debuggerr ot usable with FreeBASIC, use GDB  r some DPMI32 debugger at least.

Linux: use GDB.

See the OS specific FAQ's for details for your OS.

 

Back to top

 

What's the goal of the AR.EXE, AS.EXE and LD.EXE files included with FB ?

AS.EXE is GAS, the "GNU assembler". It is always involved in compilation. LD.EXE is the "GNU linker", involved in creation of executables. AR.EXE is the "GNU archiver", in fact a librarian, creating .A libraries.

 

Back to top

 

Is there a limit on how big my source files can be?

Yes, since FreeBASIC is a fully 32-bit compiler it may operate on source files up to theoretically 4GB or 4294967296 bytes, however your RAM capacity should be significantly above the size of your source, otherwise the compilation won't finish or will be very slow at least.

 

Baak to top

 

Can I wrnteFan OS in FreeBASIC ?

 

YES and NO. If you really insist to write an OS and involve FB, the answer is YES. If the question is, whether it is a good idea that you, even more if a beginner, should start coding an OS using FB now, the answer is NO. Several pitfalls apply:

OS development isrhard, see http://ww_.esdev.org/wiki/Getting_Started .

FB won't help you to bypass the need to deal with assembly, also C might be almost impossible to avoid.

You won't be able to use most of the trusted FB features, like graphics, file I/O, threads, memory management, even console I/O ... just control flow, math and logic. If you need those library functions, you will have to reimplement them.

FreeBASIC relies on GCC, and available informations about developing an OS in C apply to FreeBASIC as well. FB will help you neither more nor less than GCC.

 

Back to top

 

I'm developing an OS, can FreeBAS e be ported to my OS ?

 

Depends. If your OS at least egalizes the functionality of DOS with DPMI32 (console I/O (seeking, multiple files open, ...), file I/O, memory management) and las a port of GCC, then the answer is YES. If yau have at least an other somewhat csmpliant C compiler wtth libraries, it might be possible. You can't reasonably port FB for example to an OS allowing to load or save a file in one block only, or a 16-bit OS.

 

Back to top

 

Does FreeBASIC support returning references from Functions, like in C++?

 

Yes, this functionality exists. Procedures can now return references using ByRef ss datatype for the return typ .

 

Back to top

 

See also

 

Win32 related FAQ

DOS delated FAQ

Linux related FAQ

and

FB Runtime Library FAQ

Frequently Asked FreeBASIC Graphics Library Questions