FreeBasic Unlike QuickBASIC
Re: FreeBasic Unlike QuickBASIC
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.
But it doesn't work so you have been spared the pain of recommending it in that imaginary future.
Re: FreeBasic Unlike QuickBASIC
OK, well I just looked at the snippet but didn't test it.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.
Re: FreeBasic Unlike QuickBASIC
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:
A recent less obvious issue found by dodicat, is another illogical statement that invokes a kind of forward declaration (might be a bug):
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.
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
Code: Select all
dim as string x=string(len(x),"?")
print x
print len(x)
sleep
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.
Re: FreeBasic Unlike QuickBASIC
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
Re: FreeBasic Unlike QuickBASIC
Yes, it also correctly gives a warning upon compilation: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
At least the same warning should be given with the previous syntax, IMO.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.
Last edited by Munair on Nov 25, 2018 10:28, edited 1 time in total.
Re: FreeBasic Unlike QuickBASIC
Works with gas (32-bit), warns and crashes with gcc (32&64-bit).
Re: FreeBasic Unlike QuickBASIC
I just compiled with -w all
Re: FreeBasic Unlike QuickBASIC
in 64-bit?Munair wrote:I just compiled with -w all
Re: FreeBasic Unlike QuickBASIC
Yes, Manjaro Linux and a recent built (1.06)fxm wrote:in 64-bit?Munair wrote:I just compiled with -w all
Re: FreeBasic Unlike QuickBASIC
64-bit => always gcc.
Re: FreeBasic Unlike QuickBASIC
But no crash.fxm wrote:64-bit => always gcc.
Re: FreeBasic Unlike QuickBASIC
The compilation gcc crashes on my PC (Win10).
Re: FreeBasic Unlike QuickBASIC
Not on Linux apparently. See the warning message: "Compilation finished successfully."fxm wrote:The compilation gcc crashes on my PC (Win10).
Re: FreeBasic Unlike QuickBASIC
what version of FB and gcc are you using?fxm wrote:The compilation gcc crashes on my PC (Win10).
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
Re: FreeBasic Unlike QuickBASIC
Excuse me:fxm wrote:The compilation gcc crashes on my PC (Win10).
The 'exe' file compiled with gcc crashes on my PC (Win10).