Page 1 of 1
Ambiguous variables
Posted: Tue Jan 26, 2016 12:42 pm
by Victorio
Hi,
I have many many warnings, when I compiling my program.
All warnings are two types :
[Warning] INFOKAT.PRG(22): XBT0103: Ambiguous variable reference, assuming MEMVAR verzia
and
[Warning] INFOKAT.PRG(267): XBT0102: Ambiguous variable reference fontbt
I have in MAIN() define PUBLIC variable like this :
PUBLIC verzia
and then in source have for example this :
verzia="Version 2.0"
or PUBLIC abc[2]
and later in some function :
abc[1]:="alfastring"
abc[2]:="betastring"
what is wrong in this ?
I tryed also write :
PUBLIC verzia:=""
and next
verzia:="Version 2.0", but no effect
when write
PUBLIC verzia:="Version 2.0", in this case no warning.
can I ignore all ?
Victorio.
Re: Ambiguous variables
Posted: Tue Jan 26, 2016 1:03 pm
by rdonnay
You are using the /W switch of the compiler.
This forces the compiler to warn you that you have variables which may not be defined.
This only happens with private and public variables and field names.
It is always a good idea to declare all variables as LOCAL if you don't want these warnings.
You can also turn off the warnings by removing the /W option from your project file.
True compilers try to resolve everything during compiling to prevent runtime errors.
This is true of C and C++.
Xbase++, on the other hand, is compatible with Clipper legacy code and therefore it must allow variables to be created at runtime.
There are many advantages to this capability, but also disadvantages because the programmer cannot always prevent coding errors.
Ambiguous warnings are not an indication that your code will fail. It only is an indication that the compiler does not know the origin of the variable. Private and Public variables should be used rarely.
Re: Ambiguous variables
Posted: Tue Jan 26, 2016 1:58 pm
by Cliff Wiernik
If you want to get right of the warnings and need to have the private/public variables, make them not ambigous.
For example.
PUBLIC pubvar
PRIVATE memvar
memvar := 'A' // generates warning
pubvar := 'B' // generates warning
m->memvar := 'A' // no warning
m->pubvar := 'B' // no warning
REPLACE dbffield with m->memvar // generates warning
REPLACE ALIASNAME->dbffield with m->memvar // no warning
We have old code in our application that we have not converted to use locals. New code uses local. This removes the warnings as we always compile with the /w flag on to catch some typo type errors.
Re: Ambiguous variables
Posted: Tue Jan 26, 2016 3:13 pm
by Auge_Ohr
as Roger say : it is just a Warning.
if you want to get rid of the Warning you have to write MEMVAR before declare
Code: Select all
MEMVAR verzia
PROCEDURE MAIN
PUBLIC verzia
Re: Ambiguous variables
Posted: Wed Jan 27, 2016 2:13 am
by Victorio
I will try it, thank you.
I was thinking then also warning can cause some incorrect behavior at runtime.
Re: Ambiguous variables
Posted: Wed Jan 27, 2016 7:15 am
by bwolfsohn
Victorio wrote:I will try it, thank you.
I was thinking then also warning can cause some incorrect behavior at runtime.
it it's a misspelled variable, then you will have a problem at runtim..
if it's a public or private variable that you haven't prefixed with m-> then you should be ok..
I leave the /w switch on. it warns me about misspellings, and that saves a lot of time.