| ??? 09/08/06 06:02 Read: times |
#123896 - Magic numbers Responding to: ???'s previous message |
Mark Buster said:
Regarding the "magic numbers", The reason I did it this way is that this chunk of code is just one of multiple serial frame handlers, which all have a LEN,TYPE,CMD, etc, which will be different values within the different handlers, therefore a #define is not going to work for this situation.. Just adopt a naming convention that distinguishes amongst the different protocols; eg // X-MODEM Definitions #define XM_LEN #define XM_TYPE #define XM_CMD // Y-MODEM Definitions #define YM_LEN #define YM_TYPE #define YM_CMD // Z-MODEM Definitions #define ZM_LEN #define ZM_TYPE #define ZM_CMDOr just keep them in separate files. Note how, in your original code, you had to write in the comment for each "magic number" assignment which was LEN,TYPE,CMD, etc; by using symbolic names, you remove the need to do this! |
| Topic | Author | Date |
| ^= , Checksum, Problem | 01/01/70 00:00 | |
| Have you tried a simulator? | 01/01/70 00:00 | |
| well, | 01/01/70 00:00 | |
| OK | 01/01/70 00:00 | |
| volatile? | 01/01/70 00:00 | |
| volatile | 01/01/70 00:00 | |
| using ICE ? | 01/01/70 00:00 | |
| update code (working) and clarification | 01/01/70 00:00 | |
| Style | 01/01/70 00:00 | |
| Think about your variable types | 01/01/70 00:00 | |
| Thanks | 01/01/70 00:00 | |
| Magic numbers | 01/01/70 00:00 | |
| but don't be "oversmart" | 01/01/70 00:00 | |
| example? | 01/01/70 00:00 | |
| advantages | 01/01/70 00:00 | |
the most often forgotten quality guarantee | 01/01/70 00:00 | |
| so, use structures! | 01/01/70 00:00 | |
| padding | 01/01/70 00:00 | |
| | 01/01/70 00:00 | |
| Actual Output | 01/01/70 00:00 | |
| C99 | 01/01/70 00:00 | |
| making up your own | 01/01/70 00:00 | |
| Names | 01/01/70 00:00 | |
| FYI - C99 Exact- & Minimum-width types | 01/01/70 00:00 |



