Variable scope

65 views
Skip to first unread message

slar...@gmail.com

unread,
Nov 9, 2021, 3:42:36 PM11/9/21
to Harbour Users
I have 2 questions

1) is there a function that can return the scope of a variable
    ex : nTest => LOCAL | STATIC etc...

2) Unable to remember a technicality
     within a function if we do not declare a variable what is the scope of the
     variable ? PRIVATE or LOCAL

     EX :
    FUNCTION Test()
        LOCAL x := 10

         y := 20

        // What is scope of variable y since it's not declared ?

    RETURN( NIL )

thanks

Sylvain Larche
Consultant

Auge & Ohr

unread,
Nov 10, 2021, 1:37:05 AM11/10/21
to Harbour Users
hi,


> 1) is there a function that can return the scope of a variable
i know Debugger can do it ... but not "how"

LOCAL and STATIC ( not Filed-wide STATIC ) can only be reached in Func/Proc or when pass as Parameter


> 2) Unable to remember a technicality
     within a function if we do not declare a variable what is the scope of the
     variable ?

un-declare Variable are PRIVATE.
PRIVATE and PUBLIC must be declare as MEMVAR when using Compiler Option -w1 -es2

i recommend to use PRIVATE and PUBLIC only when need else it will be hard to find a Variable e.g. in Debugger

Jimmy
Reply all
Reply to author
Forward
0 new messages