Thread: Quick Question on Multiple Source Files

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    how often do you guys tend to use global variables anyway?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by dac
    how often do you guys tend to use global variables anyway?
    I use them quite frequently. But I never show any of my sourcecode to anybody. That saves me from a lot of discussions about their usefullness.
    Kurt

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    In general, global variables should be avoided unless the programmer has a good
    reason to use one. In this case, using a static is just hte same, it lasts for the length
    of the programs life time and retains its value throughout function calls.
    Double Helix STL

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by swgh
    In general, global variables should be avoided unless the programmer has a good
    reason to use one. In this case, using a static is just hte same, it lasts for the length
    of the programs life time and retains its value throughout function calls.
    how do you guys think i could eliminate the global variables? the program is a for a car breakers (structs a bit of a give away lol), all 15 of the modules are local but i have 4 which arent, holding number of customers which is used by most modules same with vehicles, and also the data structs need to be used by each modules too.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    how do you guys think i could eliminate the global variables?
    It is you, who should think about it.
    If you call some funtion you can pass everithing it needs as parameters instead of accessing globals
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create a C project with multiple source files
    By MSF1981 in forum C Programming
    Replies: 5
    Last Post: 03-22-2009, 09:25 AM
  2. Working with multiple source files
    By abh!shek in forum C Programming
    Replies: 17
    Last Post: 06-03-2008, 11:23 AM
  3. Mutex across multiple source files
    By Quasar in forum Linux Programming
    Replies: 7
    Last Post: 12-04-2007, 08:25 AM
  4. pseudocode for multiple source files
    By Calef13 in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2007, 09:07 AM
  5. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM