Announcement

Collapse
No announcement yet.

What happens in this situation...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mark smit
    Guest replied
    HeHeHe!!

    I was wondering if anybody else was gonna notice those names Borje

    ------------------
    Cheers

    Leave a comment:


  • Borje Hagsten
    replied
    Be careful though. Trying to put ID software's John Carmack and
    Bill Gates in same room may result in some real serious GPF's..


    ------------------

    Leave a comment:


  • Don Dickinson
    replied
    It works because you're passing Person as a parameter. This effectively makes Person a local variable. Local varaibles override globals when they are named the same.
    --Don


    ------------------
    www.basicguru.com/dickinson

    Leave a comment:


  • mark smit
    Guest replied
    Here is a better example of what I mean...
    Code:
    rem test
    rem
    #compile exe
    
    
    type CPerson
        Age as long
        FirstName as asciiz * 64
        LastName as asciiz * 64
    end type
    
    
    global Person as CPerson
    
    function MakePerson(Person as CPerson,byval Age as long,byval FirstName as string,byval LastName as string) as long
        Person.Age = Age
        Person.FirstName = FirstName
        Person.LastName = LastName
    end function
    
    
    function pbmain as long
        dim Other as CPerson
        
        MakePerson Person,38,"Bill","Gates"
        MakePerson Other,32,"John","Carmack"
        
        msgbox Person.FirstName & $CRLF & Other.FirstName
    end function

    The variable "Person" is a global and also used as a parameter in the function MakePerson. It seems to work but I'm not clear on why.

    ------------------
    Cheers

    Leave a comment:


  • mark smit
    Guest started a topic What happens in this situation...

    What happens in this situation...

    Hi guys,


    I was hoping somebody could explain to me what exactly happens when you have a global variable, we'll call it SESSION, and you use the same name in a functions parameter list.


    Code:
    type CSession
        m_Number as long
    end type
    
    global Session as CSession
    
    function OpenSession(Session as CSession) as long
        Session.m_Number = 2048
    end function
    Is this even legal or is the compiler just missing this?


    does the parameter act as a local variable inside the function and not even see the global variable?

    ------------------
    Cheers

    [This message has been edited by mark smit (edited February 06, 2001).]
Working...
X