Harbour warning level

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Harbour warning level

Post by l3whmg »

Hello to everyone
Is there someone can help me to understand why the Harbour compiler generates a warning when compiling the code below?

Code: Select all

Line 01 MEMVAR _HMG_SYSDATA
Line 02 
Line 03 #include "hmg.ch"
Line 04 
Line 05 FUNCTION main()
Line 06 
Line 07  LOCAL cLocalVar := ""
Line 08 
Line 09  cLocalVar := GetCurrentFolder()
Line 10 
Line 11  MSGSTOP( cLocalVar )
Line 12 
Line 13 RETURN NIL
Line 14 
Line 15 FUNCTION Other()
Line 16 
Line 17  LOCAL cLocalVar
Line 18 
Line 19  cLocalVar := GetCurrentFolder()
Line 20 
Line 21  MSGSTOP( cLocalVar )
Line 22 
Line 23 RETURN NIL
This is the message IF the source is compiled with warning level 3
hbmk2: Processing configuration: D:\HMG\MiniGui\harbour\bin\hbmk.cfg
Harbour 2.0.0 (Rev. 13372)
Copyright (c) 1999-2010, http://www.harbour-project.org/
hbwarntest.prg(15) Warning W0032 Variable 'CLOCALVAR' is assigned but not used in function 'MAIN(7)'
If I set warning level to zero no message displayed (of course)

As you can see, in one case raises the alert while the other not.

Is there a solution to use

Code: Select all

LOCAL cVar := "value"
without warning with level 3?

Best regards
Luigi from Italy
www.L3W.it
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: Harbour warning level

Post by jparada »

Hi Luigi,

I think you also have to declare MEMVAR cLocalVar.

Regards
Javier
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Harbour warning level

Post by l3whmg »

Hi Javier, many thanks for your fast replay, but...this it's not the solution :cry:
In fact two things:
MEMVAR is a declaration statement .... At runtime, the specified variables must be created using the PRIVATE, PARAMETERS or PUBLIC....
. No required for LOCAL. Any way, I tried your suggestion with the same warning.

In my source I've used two times the same var in two different function, but in one case I've used

Code: Select all

LOCAL cLocalVar := ""
and in other

Code: Select all

LOCAL cLocalVar
(without assigned value); only the first row give me warning :!:

Any way many thanks.
Luigi from Italy
www.L3W.it
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: Harbour warning level

Post by Carlos Britos »

l3whmg wrote:Hi Javier, many thanks for your fast replay, but...this it's not the solution :cry:
In fact two things:
MEMVAR is a declaration statement .... At runtime, the specified variables must be created using the PRIVATE, PARAMETERS or PUBLIC....
. No required for LOCAL. Any way, I tried your suggestion with the same warning.

In my source I've used two times the same var in two different function, but in one case I've used

Code: Select all

LOCAL cLocalVar := ""
and in other

Code: Select all

LOCAL cLocalVar
(without assigned value); only the first row give me warning :!:

Any way many thanks.
Hi l3whmg
Is the normal Harbour behaviour of switch -w3
If you assign the "" to cLocalVar and later in the code assign another value then the first assignement is unused, but if you set LOCAL cLocalVar := "" and later use: cLocalVar += "something" then there is no warning.
Regards/Saludos, Carlos (bcd12a)
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Harbour warning level

Post by Rathinagiri »

If you assign the "" to cLocalVar and later in the code assign another value then the first assignement is unused, but if you set LOCAL cLocalVar := "" and later use: cLocalVar += "something" then there is no warning.
Nice explanation Carlos. Thanks.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Harbour warning level

Post by l3whmg »

Hi Carlos, many thanks for you answer.
I had sensed this "behaviour" but I was hoping there was an alternative.
Any way, I will try to align the source code to this rule.
Many thanks
Luigi from Italy
www.L3W.it
Post Reply