FreeBasic Unlike QuickBASIC

General discussion for topics related to the FreeBASIC project or its community.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBasic Unlike QuickBASIC

Post by dodicat »

I suppose Munair, that had it worked and had you wanted to change a name sometime in the imaginary future, then you would have had to change the offset name also.
But it doesn't work so you have been spared the pain of recommending it in that imaginary future.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

dodicat wrote:I suppose Munair, that had it worked and had you wanted to change a name sometime in the imaginary future, then you would have had to change the offset name also.
But it doesn't work so you have been spared the pain of recommending it in that imaginary future.
OK, well I just looked at the snippet but didn't test it.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

I use FreeBASIC for over a year now (not counting some tries in earlier years) and at this point the overall FEEL I get compared to QuickBASIC in particular, is that while FreeBASIC's keywords are practically the same, some important features, most notably pointers and their syntax, make it much more C like. FreeBASIC is powerful and unlike QuickBASIC, you need to know what you're doing; there are less safe guards in place so to speak, and it is relatively easy to get a *** stack smashing detected *** crash as this (illogical) example demonstrates:

Code: Select all

type Typed64Bits
    value as string * 8
end type

type TypedLongInt
    value as longint
end type

function LongIntBStr(byval value as longint) as string
	dim n as TypedLongInt
	dim s as Typed64Bits
	n.value = value
	lset s = n
	return *cptr(string ptr, @(s.value))
end function

function LongIntBVal(byval value as string) as longint
	dim s as Typed64Bits
	dim n as TypedLongInt
	s.value = value
	lset n = s
	return n.value
end function

' TESTING
dim as longint v1 = rnd * 9223372036854775807
dim as string s1 = LongIntBStr(v1)
	print LongIntBVal(s1) 

end
A recent less obvious issue found by dodicat, is another illogical statement that invokes a kind of forward declaration (might be a bug):

Code: Select all

dim as string x=string(len(x),"?")
print x
print len(x)
sleep
These examples are not meant to downgrade FreeBASIC in any way. It just tells one to be careful and to know exactly what you're doing. In contrast, I think the worst errors I got in QuickBASIC (if I remember correctly) were memory related, like stack overflow with recursion and out of memory with large arrays on the heap.
Bottomline, FreeBASIC looks a lot like QuickBASIC but that's only on the outside.
Last edited by Munair on Nov 25, 2018 9:35, edited 1 time in total.
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

By cons, the dynamic version (using New) of your second example works:

Code: Select all

dim as string ptr ps = new string(string(len(*ps),"?"))
print *ps
print len(*ps)
sleep
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

fxm wrote:By cons, the dynamic version (using New) of your second example works:

Code: Select all

dim as string ptr ps = new string(string(len(*ps),"?"))
print *ps
print len(*ps)
sleep
Yes, it also correctly gives a warning upon compilation:
fixed1.c: In function ‘main’:
fixed1.c:34:15: warning: ‘PS$0’ may be used uninitialized in this function [-Wmaybe-uninitialized]
int64 vr$3 = fb_StrLen( (void*)PS$0, -1ll );
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation finished successfully.
At least the same warning should be given with the previous syntax, IMO.
Last edited by Munair on Nov 25, 2018 10:28, edited 1 time in total.
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

Works with gas (32-bit), warns and crashes with gcc (32&64-bit).
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

I just compiled with -w all
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

Munair wrote:I just compiled with -w all
in 64-bit?
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

fxm wrote:
Munair wrote:I just compiled with -w all
in 64-bit?
Yes, Manjaro Linux and a recent built (1.06)
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

64-bit => always gcc.
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

fxm wrote:64-bit => always gcc.
But no crash.
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

The compilation gcc crashes on my PC (Win10).
Munair
Posts: 1286
Joined: Oct 19, 2017 15:00
Location: Netherlands
Contact:

Re: FreeBasic Unlike QuickBASIC

Post by Munair »

fxm wrote:The compilation gcc crashes on my PC (Win10).
Not on Linux apparently. See the warning message: "Compilation finished successfully."
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: FreeBasic Unlike QuickBASIC

Post by srvaldez »

fxm wrote:The compilation gcc crashes on my PC (Win10).
what version of FB and gcc are you using?
I tried the following and both compile with the warning
FreeBASIC-1.06.0-win64\fbc -w all -asm intel -gen gcc -Wc -O2 -v "%f"

Code: Select all

untitled10.c: In function 'main':
untitled10.c:33:15: warning: 'PS$0' is used uninitialized in this function [-Wuninitialized]
  int64 vr$3 = fb_StrLen( (void*)PS$0, -1ll );
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation finished successfully.

Code: Select all

FreeBASIC Compiler - Version 1.06.0 (05-07-2017), built for win64 (64bit) standalone
gcc.exe (x86_64-win32-seh, Built by MinGW-W64 project) 4.8.2

FreeBASIC Compiler - Version 1.06.0 (08-26-2018), built for win64 (64bit) standalone
gcc.exe (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0
please also show your compile command
fxm
Moderator
Posts: 12109
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: FreeBasic Unlike QuickBASIC

Post by fxm »

fxm wrote:The compilation gcc crashes on my PC (Win10).
Excuse me:
The 'exe' file compiled with gcc crashes on my PC (Win10).
Post Reply