Global Objects. Good or Bad?

This is a discussion on Global Objects. Good or Bad? within the C++ Programming forums, part of the General Programming Boards category; Why is it that people always use use local objects of their main class in winmain and try to use ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    46

    Question Global Objects. Good or Bad?

    Why is it that people always use use local objects of their main class in winmain and try to use all sorts of methods to get a pointer to the object ,like lets say in wndproc using Set/GetWindowLong.
    Why dont they just use global objects simply? Whats the harm in using them?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Global variables can be altered by more any procedure in scope.......this can at times cause bugs that are hard to pin down....

    On the plus side, global variables can be good for games and the like because the variable does not need to be passed when execution jumps from 1 procedure to the next......this can lead to quicker execution as the passed variable does not need to be pushed onto the stack and then popped back......But whether that optimisation is needed or is worthwhile depends on what you are doing....normally it isnít so least privilege is a better option
    Last edited by Fordy; 04-24-2002 at 04:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to rotate child objects in 3D
    By Arianiv in forum Game Programming
    Replies: 11
    Last Post: 04-03-2008, 06:09 AM
  2. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 11:01 AM
  3. Good news, and bad news... (meaningless post, do not wast your time reading it)
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 04-05-2002, 04:27 PM
  4. Goto statements, good or bad?
    By Esparno in forum C++ Programming
    Replies: 20
    Last Post: 03-20-2002, 09:16 PM
  5. good news and bad news
    By Garfield in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 10-27-2001, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21