CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110

    How to access Global variables and functions

    How can I access global variables and function in my VC++ applications

    Thankx in advance

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: How to access Global variables and functions

    As long as the variable and function are not being declared as static in file scope, you need to declare them as extern in your calling file.

    Code:
    // Original file
    int temp;
    void foo(void);
    
    
    // Calling file 
    extern int temp;
    extern void foo(void);
    
    void bar(void)
    {
        foo();
    }

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: How to access Global variables and functions

    Of course, shared header files are much better
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110

    Thumbs up Re: How to access Global variables and functions

    Quote Originally Posted by Kheun
    As long as the variable and function are not being declared as static in file scope, you need to declare them as extern in your calling file.

    Code:
    // Original file
    int temp;
    void foo(void);
    
    
    // Calling file 
    extern int temp;
    extern void foo(void);
    
    void bar(void)
    {
        foo();
    }
    Thankx it works !!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured