Result is different in -lang qb vs. just normal compile

New to FreeBASIC? Post your questions here.
Post Reply
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Result is different in -lang qb vs. just normal compile

Post by Ed Davis »

Using: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
On Windows 10.

If I compile this with fbc foo.bas:

Code: Select all

print 78 + 34 * 9 * (45 * (23 - 15 * 4) - 8)
The output is: -511860

If I compile it with: fbc -lang qb
The output is: 12428

Why the difference?

Note that GW-Basic, PC-Basic - https://robhagemans.github.io/pcbasic/ and QB64 all print -511860.
QBasic prints "overflow".

Is that - overflow - the problem? In qb mode, integers are 16 bit?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Result is different in -lang qb vs. just normal compile

Post by fxm »

Ed Davis wrote: Nov 03, 2022 14:32 Is that - overflow - the problem? In qb mode, integers are 16 bit?
Yes for both.

f you work with the Single datatype, you will find the same result than with the fb dialect:

Code: Select all

#lang "qb"
print 78! + 34! * 9! * (45! * (23! - 15! * 4!) - 8!)
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Result is different in -lang qb vs. just normal compile

Post by deltarho[1859] »

I am not trying to be clever, but here is another way of looking at it.

Code: Select all

Dim As Short a = -511860
Print a
Sleep
I have decided not to use Short with the default dialect, using Long instead, just in case a Short variable overflows because it could be a difficult bug to find.
Post Reply