Windows 10 64-bit program compiles and runs ok as far as I can tell, but gets an array subscript warning when compiled with gcc -O2, -O3, or -Ofast optimization options. Is this something to be worried about?
The code stub below compiles and can show the warning that I am asking about if you use one of the above optimization options..
Code: Select all
#include once "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using FB '' Keyboard scan code constants are stored in the FB namespace in lang FB
#endif
'
type TESTDATA__type
A as ulongint
B as ulongint
C as ulongint
end type
dim shared as TESTDATA__type gTestData
' ------------------------------------------------------------
sub Wait_For_ESC_or_CtrlC__Then_Return()
' Clear Inkey buffer
While Inkey <> "": Wend
Do
Sleep 25
If MultiKey(SC_ESCAPE) Then ' [ESC] key?
exit do
end if
If MultiKey(SC_CONTROL) And MultiKey(SC_C) Then ' [CTRL+C] key combination?
exit do
end if
Loop
end sub
' ------------------------------------------------------------
sub Wait_For_ESC__Then_Return()
' Clear Inkey buffer
While Inkey <> "": Wend
Do
Sleep 25
loop until inkey = chr(27) ' [ESC] key?
end sub
' ------------------------------------------------------------
Function read_testdata_file() as integer
dim as integer f
f = freefile()
open "TESTDATA.DAT" for input as #f
If Err > 0 Then
' << You folks shouldn't have a TESTDATA.DAT file, so you should be in this error handler >>
Print "Error opening TESTDATA.DAT"
Wait_For_ESC_or_CtrlC__Then_Return() '' << MultiKey() HANGS >>
'''Wait_For_ESC__Then_Return() " << InKey() WORKS >>
print "inside - after the Open ERR wait()"
close #f
return 1
end if
print "inside - after good file open()"
'
dim as string keys(1 to 3)
input #f, keys(1), _
keys(2), _
keys(3)
If Err > 0 Then
Print "Error reading TESTDATA.DAT"
Wait_For_ESC_or_CtrlC__Then_Return()
'''Wait_For_ESC__Then_Return()
print "inside - after the Read ERR wait()"
close #f
return 2
end if
print "inside - after good file read()"
'
close #f
'
gTestData.A = val(keys(1))
gTestData.B = val(keys(2))
gTestData.C = val(keys(3))
'
RETURN 0
end Function
' ============================================================
print "main - before the testdata file read()"
read_testdata_file()
print "main - after the testdata file read()"
'
end
Code: Select all
Successful Compile (Errors 0 Warnings 0)
Primary Source: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.bas
Target Compilation: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.exe (73 KB, 74240 bytes)
Compile Time: 0.2 seconds (2021-04-10 10:52:22)
Command Line:
D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\fbc64.exe -m "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.bas" -v -s console -gen gcc -Wc -Ofast -x "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.exe"
FreeBASIC Compiler - Version 1.07.1 (2020-05-19), built for win64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target: win64, x86-64, 64bit
compiling: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.bas -o D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.c (main module)
compiling C: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\bin\win64\gcc.exe -m64 -march=x86-64 -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format -masm=intel "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.c" -o "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.asm" -Ofast
D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.c: In function 'READ_TESTDATA_FILE':
<<< ===== >>>
D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.c:152:27: warning: array subscript -1 is below array bounds of 'FBSTRING[3]' {aka 'struct <anonymous>[3]'} [-Warray-bounds]
*(FBSTRING**)&tmp$13$1 = (FBSTRING*)((uint8*)KEYS$1 + -24ll);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<<< ===== >>>
assembling: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\bin\win64\as.exe --64 --strip-local-absolute "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.asm" -o "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.o"
linking: D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\bin\win64\ld.exe -m i386pep -o "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.exe" -subsystem console "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64\fbextra.x" --stack 1048576,1048576 -s -L "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64" -L "." "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64\crt2.o" "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64\crtbegin.o" "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64\fbrt0.o" "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\Untitled1.o" "-(" -lfbgfx -lgdi32 -lwinmm -luser32 -lfb -lgcc -lmsvcrt -lkernel32 -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "D:\FB_WinFBE\WinFBE_Suite\FreeBASIC-1.07.1-gcc-8.4\lib\win64\crtend.o"
CBruce