??? 09/08/06 23:29 Read: times |
#123946 - advantages Responding to: ???'s previous message |
Jan Waclawek said:
While most of the time using symbolic names for constants is benefitial, there are ocassions, when it is not. I fully agree - see: http://www.8052.com/forum/read.phtml?id=123911 A somewhat forced example, if LENGTH would be defined in some header file, far away, and it is crystal clear from the context of program where LENGTH is used that it must be for example an even number, it might happen that somebody would change LENGTH to an invalid - odd - number when looking only at the header. Unfotunately, this is probably not a good illustration of your point! One of the real advantages of symbolic constants is that they allow you to automatically protect against such accidental inconsistencies; eg, #if (LENGTH & 0x01) == 1 #error LENGTH must be even! #endif Of course, symbolic names in themselves are no magic bullet - you still have to think carefully about devising a meaningful name, and the definition should be fully commented; eg, #define LENGTH 8 /* Length of the frame; */ /* Note that the length must be even! */ |
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 |