??? 07/11/08 17:30 Read: times |
#156623 - Initializing variables in header files... |
I was just reading a few of the Keil discussion threads, along with "Recommended Style and Coding Standards" thing Michael Karas has here at 8052.com, and realize that nobody seems to think it's a good idea to initialize things in a header file.
I'd like to show you an example header file of mine, and ask for any constructive input on why or why_not this method might be preferrable... An example of a memory map file of mine: #ifndef _MEM_MAP_H #define _MEM_MAP_H /* Compiler conditional : Parent module sees as function prototypes, all else see external */ #ifdef _MEM_MAP_C #define externMEMORY #define BitMEMORY sbit #else #define externMEMORY extern #define BitMEMORY bit #endif o o o /* multiple pressure settings defined... */ externMEMORY code float Pressures[ NUMBER_OF_PRESSURES ] #ifdef _MEM_MAP_C = { 35.0, 45.0} #endif ; o o o externMEMORY volatile BYTE bdata DigitalOutPort1; // image of dig out port 1 o o o externMEMORY BitMEMORY ChamberCoolingFan // Chamber Cooling Fan 1=ON, 0=OFF #ifdef _MEM_MAP_C /* RLYPNL-OUT4: drives signal OUT_AUX_00 on pin 3 of relay panel interface */ = DigitalOutPort1 ^ 4 #endif ; externMEMORY BitMEMORY SystemPowerRelay // System Power relay 1=ON, 0=OFF #ifdef _MEM_MAP_C /* RLYPNL-OUT3: drives signal OUT_SYSTEM_POWER on pin 5 of relay panel interface */ = DigitalOutPort1 ^ 3 #endif ; o o o externMEMORY volatile BYTE xdata FrontPanelLights // front panel lights #ifdef _MEM_MAP_C /* BOARD SELECT 2 - port 0: - address 0xFE20 */ _at_ 0xFE20 #endif ; Then, in all of the modules that need access to these variables and ports, I can simply include this header file. In only one, typically the module that contains the main() function, I define _MEM_MAP_C prior to including the header. For me, it provides a single place where all of my memory mapped variables are located, which makes maintenance easier for me. It's also pretty easy to read (at least for me it is)... Anybody else use this kind of technique? Anybody see any draw-backs to this approach? I was just wondering... -Dave |
Topic | Author | Date |
Initializing variables in header files... | 01/01/70 00:00 | |
Defintions only in source files | 01/01/70 00:00 | |
Coincidental Cohesion | 01/01/70 00:00 | |
and yet... | 01/01/70 00:00 | |
Quite possibly | 01/01/70 00:00 | |
Memory mapping | 01/01/70 00:00 | |
Now... | 01/01/70 00:00 | |
RE: just saved myself some extra typing | 01/01/70 00:00 | |
Resources | 01/01/70 00:00 | |
Another problem | 01/01/70 00:00 | |
Abort, End, Exit Procudure and Shutdown. | 01/01/70 00:00 | |
I guess I gave it significant consideration | 01/01/70 00:00 | |
RE: verbose, over conditionalized | 01/01/70 00:00 |