Ambiguous variables

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Ambiguous variables

#1 Post 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.

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Ambiguous variables

#2 Post 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.
The eXpress train is coming - and it has more cars.

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Ambiguous variables

#3 Post 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.

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Ambiguous variables

#4 Post 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
greetings by OHR
Jimmy

Victorio
Posts: 621
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Ambiguous variables

#5 Post by Victorio »

I will try it, thank you.
I was thinking then also warning can cause some incorrect behavior at runtime.

bwolfsohn
Posts: 648
Joined: Thu Jan 28, 2010 7:07 am
Location: Alachua, Florida USA
Contact:

Re: Ambiguous variables

#6 Post 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.
Brian Wolfsohn
Retired and traveling around the country to music festivals in my RV.
OOPS.. Corona Virus, so NOT traveling right now...
http://www.breadmanrises.com
FB travel group: The Breadman Rises

Post Reply