Thread: Global enum?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Arrow Global enum?

    Is it possible to make an enum statement avail its contents across all source files in a multi-file C project, or is it necessary to just use them within a .h file and localise their use as much as possible?

    Also, would anyone be able to suggest some strategies or references for reducing the amount of global variables in general? I'm finding I need to use extern a lot more than I'd like.

    Thanks!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you can define enum type in the header as you define struct

    you will declare enum var in a function that needs it

    to avoid globals - pass the needed data as parameters
    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

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If you have enums or other items that are used a lot, you could put their declarations in one main important header file that your other .c files will need to include. I imagine the overhead of doing this only really becomes insignificant when you have a lot of .c files that require a lot of data types.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Global objects and exceptions
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 07:37 AM
  3. compiler error with global enum
    By Mark S. in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2006, 08:15 AM
  4. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 10:06 AM
  5. defining and using a global class
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2004, 09:51 PM