Jump to content

FreeBASIC

From Wikipedia, the free encyclopedia
FreeBASIC
ParadigmProcedural,object-oriented
Designed byAndre Victor[1]
DeveloperThe FreeBASIC Development Team
First appeared2004;20 years ago(2004)
Stable release
1.10.1 / December 25, 2023;9 months ago(2023-12-25)
Typing disciplineStatic
OSMS-DOS,FreeBSD,Linux,Microsoft Windows
LicenseGNU GPLv2+,Standard libraries licensed under the GNU LGPLv2+
Websitewww.freebasic.net
Influenced by
QuickBASIC,C

FreeBASICis afree and open sourcemultiplatformcompilerandprogramming languagebased onBASIClicensed under theGNU GPLforMicrosoft Windows,protected-modeMS-DOS(DOS extender),Linux,FreeBSDandXbox.The Xbox version is no longer maintained.[2]

According to its official website,[3]FreeBASIC provides syntax compatibility withprogramsoriginally written inMicrosoft QuickBASIC(QB). Unlike QuickBASIC, however, FreeBASIC is a command line onlycompiler,unless users manually install an externalintegrated development environment(IDE) of their choice.[4]

Compiler features

[edit]

On itsbackend,FreeBASIC makes use ofGNU Binutilsin order to produce console andgraphical user interfaceapplications. FreeBASIC supports the linking and creation ofCstatic and dynamiclibrariesand has limited support forC++libraries. As a result, code compiled in FreeBASIC can be reused in most native development environments.

While not anoptimizing compiler,FreeBASIC can optionallytranscompileto C to compile with optimizations. FreeBASIC supportsinline assembly,multi-threading,and does not useautomatic garbage collection.

C style preprocessing,including multilinemacros,conditional compiling and file inclusion, is supported. The preprocessor also has access to symbol information and compiler settings, such as thelanguage dialect.

Syntax

[edit]

Initially, FreeBASIC emulated Microsoft QuickBASIC syntax as closely as possible. Beyond that, the language has continued its evolution. As a result, FreeBASIC combines several language dialects for maximum level of compatibility with QuickBASIC and full access to modern features.[5]New features include support for concepts such asobjects,operator overloading,function overloading,namespacesand others.[6]

Newlinecharacters indicate the termination of programming statements. A programming statement can be distributed on multiple consecutive lines by using the underscoreline continuation char(_), whereas multiple statements may be written on a single line by separating each statement with acolon(:).

Blockcomments,as well as end-of-line remarks are supported. Full line comments are made with anapostrophe',while blocks of commented code begin with/'and end with'/.

FreeBASIC is not case-sensitive.

Graphics library

[edit]

FreeBASIC provides built-in, QuickBASIC compatible graphics support through FBgfx, which is automatically included into programs that make a call to theSCREENcommand. Its backend defaults toOpenGLonLinuxandDirectXonMicrosoft Windows.This abstraction makes FBgfx graphics code cross-platform compatible. However, FBgfx is not hardware accelerated.

Users familiar with external graphics utilities such as OpenGL or the Windows API can use them without interfering with the built-in graphics library.

Language dialects

[edit]

As FreeBASIC has evolved, changes have been made that required breaking older-styled syntax. In order to continue supporting programs written using the older syntax, FreeBASIC now supports the following dialects:

  • The default dialect (-lang fbas acommand-line argument) supports all new compiler features and disallows archaic syntax.
  • The FB-lite dialect (-lang fblite) permits use of most new, non-object-oriented features in addition to older-style programming. Implicit variables, suffixes,GOSUB/RETURN,numeric labelsand other features are allowed in this dialect.
  • The QB dialect (-lang qb) attempts to replicate QuickBASIC behavior and is able to compile many QuickBASIC programs without modification.

Example code

[edit]

Standard programs, such as the"Hello, World!" programare done just as they were in QuickBASIC.

Print"Hello, World!"

sleep:end'Comment, prevents the program window from closing instantly

FreeBASIC adds to this with support forobject-orientedfeatures such asmethods,constructors,dynamic memory allocation,propertiesand temporary allocation.

TypeVector
Private:
xAsInteger
yAsInteger
Public:
DeclareConstructor(nXAsInteger=0,nYAsInteger=0)
DeclarePropertygetXAsInteger
DeclarePropertygetYAsInteger
EndType

ConstructorVector(nXAsInteger,nYAsInteger)
x=nX
y=nY
EndConstructor

PropertyVector.getXAsInteger
Returnx
EndProperty

PropertyVector.getYAsInteger
Returny
EndProperty
DimAsVectorPtrplayer=NewVector()

*player=Type<Vector>(100,100)
Printplayer->getX
Printplayer->getY

Deleteplayer

Sleep'Prevents the program window from closing instantly

In both cases, the language is well suited for learning purposes.

References

[edit]
  1. ^"freeBASIC about page".freeBASIC compiler.Retrieved5 February2012.
  2. ^FBWiki: FaqPgxbox
  3. ^freeBASIC Programming Language: Official Web site
  4. ^"freeBASIC official website downloads page".freeBASIC compiler.Retrieved13 May2017.
  5. ^"freeBASIC dialects".coderJeff's home page.Retrieved5 February2012.
  6. ^"Differences from QB".freeBASIC.net documentation.Retrieved5 February2012.
[edit]
IDEs