harbour / core

Portable, xBase compatible programming language and environment
https://harbour.github.io/
Other
322 stars 207 forks source link

Warning W0032 Variable 'NFOR' is assigned but not used in function 'MAIN(8)' #135

Closed NaldoDj-zz closed 7 years ago

NaldoDj-zz commented 7 years ago

function Main() local nFor as numeric local nTmp as numeric local nStep as numeric local nTotal as numeric nStep:=5 nTotal:=1000 for nFor:=1 to nTotal step nStep ? HB_RandomInt(nTmp++,nTotal) next nFor return(0)

D:\tmp\hb>c:\GitHub\core\bin\win\mingw\hbmk2 forWarning.prg hbmk2: Processando script local: hbmk.hbm Harbour 3.2.0dev (r1611161510) Copyright (c) 1999-2016, http://harbour-project.org/ Compiling 'forWarning.prg'... forWarning.prg(12) Warning W0032 Variable 'NFOR' is assigned but not used in function 'MAIN(8)'

No code generated. hbmk2: Erro: Executando o compilador Harbour (interno): 1 (c:\GitHub\core\bin\win\mingw\harbour.exe) -n2 forWarning.prg -w3 -es2 -oC:\Users\marin\AppData\Local\Temp\hbmk_cjfzxx.dir\ -ic:\GitHub\core\include -undef:.ARCH. -DPLATFORMWINDOWS -D__LITTLE_ENDIAN -DARCH64BIT__

mlacecilia commented 7 years ago

Hi, maybe declaring 'as numeric' preassigns a numerical value (probably 0) to the variable. This triggers the warning when the for reassigns the variable. JM2C Best regards.

Maurizio

Il 11/dic/2016 20:26, "Naldo DJ" notifications@github.com ha scritto:

function Main() local nFor as numeric local nTmp as numeric local nStep as numeric local nTotal as numeric nStep:=5 nTotal:=1000 for nFor:=1 to nTotal step nStep ? HB_RandomInt(nTmp++,nTotal) next nFor return(0)

D:\tmp\hb>c:\GitHub\core\bin\win\mingw\hbmk2 forWarning.prg hbmk2: Processando script local: hbmk.hbm Harbour 3.2.0dev (r1611161510) Copyright (c) 1999-2016, http://harbour-project.org/ Compiling 'forWarning.prg'... forWarning.prg(12) Warning W0032 Variable 'NFOR' is assigned but not used in function 'MAIN(8)'

No code generated. hbmk2: Erro: Executando o compilador Harbour (interno): 1 (c:\GitHub\core\bin\win\mingw\harbour.exe) -n2 forWarning.prg -w3 -es2 -oC:\Users\marin\AppData\Local\Temp\hbmk_cjfzxx.dir\ -ic:\GitHub\core\include -undef:.ARCH. -DPLATFORMWINDOWS -D__LITTLE_ENDIAN -DARCH64BIT__

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/harbour/core/issues/135, or mute the thread https://github.com/notifications/unsubscribe-auth/ACa2qoeRQ51_-NWmKKpruYJfBj5KOBXRks5rHE5GgaJpZM4LKAe- .

mlacecilia commented 7 years ago

Sorry, my previous suggestion is wrong. Same should happen for nStep and nTotal variables. Something of strange or buggy is happening. Please, try to compile this code, acting the same thing of your :

function Main() local nFor as numeric local nTmp as numeric local nTotal as numeric nTotal:=1000 for nFor := 1 to nTotal step 5 ? HB_RandomInt(nTmp++,nTotal) next nFor return(0)

On my side it compile fine. I'm asking some guru opinion about this side effect of STEP clause.

Anyway, your code is wrong because you're incrementing nTmp before to assign a numerical value to it and an error is issued running the executable. Best regards.

Maurizio

Il 11/12/2016 20:37, Maurizio la Cecilia ha scritto:

Hi, maybe declaring 'as numeric' preassigns a numerical value (probably 0) to the variable. This triggers the warning when the for reassigns the variable. JM2C Best regards.

Maurizio

Il 11/dic/2016 20:26, "Naldo DJ" <notifications@github.com mailto:notifications@github.com> ha scritto:

function Main()
local nFor as numeric
local nTmp as numeric
local nStep as numeric
local nTotal as numeric
nStep:=5
nTotal:=1000
for nFor:=1 to nTotal step nStep
? HB_RandomInt(nTmp++,nTotal)
next nFor
return(0)

D:\tmp\hb>c:\GitHub\core\bin\win\mingw\hbmk2 forWarning.prg
hbmk2: Processando script local: hbmk.hbm
Harbour 3.2.0dev (r1611161510)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'forWarning.prg'...
forWarning.prg(12) Warning W0032 Variable 'NFOR' is assigned but
not used in function 'MAIN(8)'

No code generated.
hbmk2: Erro: Executando o compilador Harbour (interno): 1
(c:\GitHub\core\bin\win\mingw\harbour.exe) -n2 forWarning.prg -w3
-es2 -oC:\Users\marin\AppData\Local\Temp\hbmk_cjfzxx.dir\
-ic:\GitHub\core\include -undef:.ARCH. -D__PLATFORM__WINDOWS
-D__LITTLE_ENDIAN__ -D__ARCH64BIT__

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/harbour/core/issues/135>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACa2qoeRQ51_-NWmKKpruYJfBj5KOBXRks5rHE5GgaJpZM4LKAe->.
vszakats commented 7 years ago

https://groups.google.com/d/msg/harbour-devel/9w3qcPvQonw/G_ELmTY0BAAJ

alcz commented 7 years ago

Test code supplied compiles without warnings (-w3) after 50083715672297e0da7e3cee47f8fb767b7d200e thanks to @druzus. This issue can be closed.

Original test code has RTE behaviour on incrementing NIL, it runs after changing

local nTmp as numeric

to

local nTmp as numeric := 1

I think it's not the syntax i'd expect, should it be the other way?

local nTmp := 1 as numeric