home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20195 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  2.3 KB

  1. Path: sparky!uunet!olivea!hal.com!decwrl!netcomsv!netcom.com!pdh
  2. From: pdh@netcom.com (Phil Howard )
  3. Newsgroups: comp.lang.c
  4. Subject: initialized extern variables, coded in 1 file, used in many
  5. Message-ID: <1993Jan26.015543.23671@netcom.com>
  6. Date: 26 Jan 93 01:55:43 GMT
  7. Organization: Netcom - Online Communication Services  (408 241-9760 guest)
  8. Lines: 47
  9.  
  10. I want to define a large set of extern variables and I want to define
  11. them in just one place (one file) so that I don't have any problems
  12. with things out of sync as I change them (changes of type for existing
  13. variables, or adding and deleting variables).
  14.  
  15. For the above would create variables in a header like:
  16.  
  17. EXTERN long var1;
  18. EXTERN int var2;
  19.  
  20. and do
  21.  
  22. #define EXTERN extern
  23.  
  24. in all files but the one where they are being exported from.  In that
  25. one file I would do
  26.  
  27. #define EXTERN
  28.  
  29. and include the header before the first block.  The choice of symbol
  30. name EXTERN is arbitrary; some other name may be used if consistent.
  31.  
  32. ---------------- NOW HERE IS THE CATCH ----------------
  33.  
  34. I want to initialize many (its ok to be required to initialize all)
  35. of these variables.  The problem is that initializers are inconsistent
  36. with the extern storage class.  But the initializers would have to be
  37. coded in the same file as the types of the variables are coded, i.e.
  38. the header.  That means the initializers would be there for those modules
  39. using the variables with the extern class.
  40.  
  41. Also, some of these variables will be very large arrays, and initializing
  42. them via some code would just not be practical.  For example, these arrays
  43. might be a set of default fonts to be used when font files are not specified
  44. or not available.  64000 assignment statements does not make much sense.
  45.  
  46. I've tried using the omitted storage class in all modules.  This results
  47. in the variables and their initial contents to be exported from all modules.
  48. This results in a lot of large object files and errors in the linker.
  49.  
  50. Has anyone tackled this organizational problem for C and solved it in some
  51. way?
  52. -- 
  53. /************************************************************************\
  54. | Phil Howard,  pdh@netcom.com,  KA9WGN    Spell protection?  "1(911)A1" |
  55. | "It's not broken... it's just functionally challenged" --Phil and Pete |
  56. \************************************************************************/
  57.