Global enum?

This is a discussion on Global enum? within the C Programming forums, part of the General Programming Boards category; Is it possible to make an enum statement avail its contents across all source files in a multi-file C project, ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    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, 08:51 PM

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