Differences from QB
- Source: https://www.freebasic.net/wiki/wikka.php?wakka=LangQB
- Last revised: 2024-03-07
FreeBASIC introduced a -lang command-line option, that is used to change the language compatibility mode. Use the -lang qb option when compiling to select the most QB compatible parser. All differences listed below assume that -lang qb was used.
Architecture/Platform incompatibilities
- FreeBASIC is written for 32-bit operating systems and a 32 bit DOS extender, and cannot utilize code which depends on 16-bit DOS, 16 bit assembly or memory model (segment & offset, XMS/EMS, ...).
DEF SEGis no longer necessary and will not work - any code whichPOKEs to video memory this way will no longer function, however, for DOS it can be easily rewritten using DPMI features.CALL INTERRUPTno longer functions, as it relies on 16-bit DOS. DOS interrupts can be called in the DOS32 version by using the DPMI library, but they might work slowly because of the 32bit-16bit-32bit mode changes the processor will have to perform.
- A scalar variable and an array with the same name and suffix can no longer share the same name.
SHAREDcan't be used inside aSUBorFUNCTIONas it resulted in shared variables not defined in the main program. A properDIM SHAREDin the main program must be used.COMMONdeclarations do not depend on the order they are made, variables are matched by name and for that reason named COMMON is no longer supported. All COMMON arrays are variable-length arrays in FB.- If a single line
IFhas an (unnecessary) colon directly after theTHEN, it has to be terminated by anEND IFin FB. If that unneeded colon is removed, FB will behave as QB.
- Graphics support was internally redesigned, see GfxLib overview
CLEARis no longer used to reset all variables and set the stack. Variables must be reset one by one, and stack size can be changed in the compiler command line. The keywordCLEARis used to do memory fills in FB.- String
DATAitems must be enclosed in quotes in FB, in QB this was optional - All functions must have been declared, even with a
CALLin FreeBASIC. WithCALLit was possible to invoke prototype-less functions in QuickBASIC. (to be supported in future with -lang qb) - In FreeBASIC all arrays must be explicitly declared. (Interpreted QuickBASIC arrays are automatically created with up to 10 indices.)
- Strings, except fixed length strings of
STRING*Ntype since fbc version 1.20.0, use a null (char0) terminator to be compatible with C libraries and the Windows API, so such fixed-length strings can't containchr$(0)chars. - When
INKEY[$] reads an extended key (Num Pad, Arrows...) it returns a two character string. In FB the first character isCHR[$](255), while in QB this first char isCHR$(0). - With fixed length strings, except fixed length strings of
STRING*Ntype since fbc version 1.20.0, FreeBASIC gives the real length asLENplus one (null-char), even onTYPEfields. - In FreeBASIC, unused characters of fixed-length strings are set to
0, regardless of what "-lang" compiler option is used. In QB, unused characters are set to32(space, or " ", in ASCII). - When a fixed-length string, except fixed length strings of
STRING*Ntype since fbc version 1.20.0, is declared, but still not initialized, all characters are set to 0, both in FreeBASIC and QB. Since fbc version 1.20.0, when a fixed-length string ofSTRING*Ntype is declared, but still not initialized, all characters are set to space. - The arrays are stored in row-major order in FB, they were stored in column-major order in QB by default. Row major order: data with consecutive last index are contiguous. Column-major order: data with consecutive first index are contiguous. For example, if you have
DIM A(1 TO 6, 1 TO 8), in row-major order the elements are stored such thatA(3,5)is followed in memory byA(3,6); in column-major orderA(3,5)is followed in memory byA(4,5). - Programs don't stop anymore on runtime errors unless -e, -ex or -exx option is used in the command line. Using these options allow the use of QB style error handling (
ON ERROR,RESUME...). - Octal numbers are written
&o..., whereas in QB they could be written as&o...or&.... - In FB
FORloops in subs/functions do not accept arguments receivedbyrefas counters. A local variable must be used. - FB's
LOCATEdoes not respect the fourth and fifth arguments for cursor shape. - FB's
SCREEN (Graphics)does not allow switching the visible or the work-page. UseSCREENSETinstead. - FB's
COLORdoes not allow a third argument for border color. - FB's
TIMERreturns the number of seconds since the computer started, while QB'sTIMERreturns the number of seconds since midnight. (Win32 and Linux only: No more wrapping at midnight! 😃) - In QB a
chr$(13)inside a string did aCR+LFwhenPRINTed. In FB theCHR(13)prints just at what it is, aCR. EOFcan no longer be used to detect an empty comms buffer. Empty buffer should be tested comparingLocwith0in FB. Also, for files opened inRANDOMorBINARYmode,EOFreturns non-zero already after reading exactly the file size, seeEof.- Integer variables do not signal overflow errors in FB, even with the -ex or -exx option on. Any QB code relying in catching integer overflow errors will not work in FB.
BSAVEandBLOADcan be used in FB only to save and retrieve screens or graphic buffers. They will work only if gfxlib is linked, this is, if a graphics screen mode is requested somewhere in the program. The console can't be saved withBSAVEor retrieved withBLOAD. The other use ofBSAVE-BLOAD, saving and loading full arrays, can be achieved easily withGETandPUT.FIELDstatement (for record definition at runtime) has been left aside. The keywordFIELDis used in FB to specify field alignment inTYPEvariables.- PC Speaker commands no longer function: Any references to
SOUNDorPLAYstatements will result in an error message. There is a third party library available to emulate this functionality, but it's not included with FreeBASIC. - Fake event-driven programming (
ON KEY,ON PEN,ON STRIG,ON TIMER) no longer works. They could be emulated by a separate library. MKSMBF$and all theMKxMBF$commands supporting the pre-QB4.0 Microsoft proprietary floating point format (MBF) are not implemented.- The use of parenthesis in the arguments passed to a function to emulate by-value passing is not permitted. The
CALLquirk resulting in all arguments being passed by value, no longer works. The properBYVALandBYREFkeywords must be used. FILESis not implemented. Instead, PDS 7.1-compatibleDIR[$] can be used.IOCTL,ERRDEVandERRDEV$, low level functions to access hardware are not implemented as they were OS-dependent.CALL ABSOLUTEto run inline machine code is no longer supported. Instead you can useASM...END ASMblocks to insert inline assembler commands. Or use theASM ...one line command.
Back to DocToc