Thread: Global Vars

  1. #1
    I'm Back
    Join Date
    Dec 2001
    Posts
    556

    Global Vars

    Is there something -ve about them ie Global Variables.
    -

  2. #2
    Unregistered
    Guest
    exposes data to all functions in prgram, which may be good or may be bad depending on the circumstances. If you want assurance that a given variable will be affected only by a given function, then keeping scope as local as possible is recommended.

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    The use of global variables is often considered a serious flaw in the design of your application, but sometimes their use is unavoidable.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    68
    Global make it more dificult to look after variable names. Once you use a global variable you have to start watching the variable names you use locally, which means you have to start using the scope resalution operator. Just makes things get tricky and get out of hand fast. They take away the elegance of a program and make it more difficult to do "black box" programming depending on how much your overusing them. They have their place though...I like to use them for DirectX sometimes. For simple programs it can be easier than passing a variable all over the place because its needed everywhere.
    ______________________
    The Gekko

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    The interesting part is that the MS Mfc model relies heavily on global member variables for all there controls. I have not found a way around that when I do win apps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global struct variable best use
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 06-05-2009, 05:08 AM
  2. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  3. About using global vars
    By Tibor in forum C Programming
    Replies: 66
    Last Post: 12-18-2008, 09:19 PM
  4. Maintaining Global Vars Between Libraries
    By Canadian0469 in forum C Programming
    Replies: 9
    Last Post: 11-27-2007, 12:29 PM
  5. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 10:06 AM