??? 09/08/06 16:50 Read: times |
#123936 - C99 Responding to: ???'s previous message |
I said:
When you start using a new compiler, you have to look-up in the Manual to find the specific type to use in each definition. Maarten Brock said:
C99[1] defines that limit.h tells what the range of the integer types is. Yes, and C89[1] also has that. So I suppose it should be possible to devise a set of conditional compilation switches that would automatically pick an appropriate "native" type. It also defines that an int can at least represent -32767 to +32767. Yes - and there's the catch! An 'int' can at least represent -32767 to +32767; ie, an 'int' must have at least 16 bits. But that's my point - it could be 16, 24, 32, 64,... In embedded stuff, you ususally want to know for sure how many bits! C99 also defines most required int types of specific size and signedness in stdint.h. No need to create your own. Just include it and use uint8_t. And C99 did this for precisely the reasons that I've said. Trouble is, many (most?) embedded 'C' compilers are not C99; Keil certainly isn't, and I think SDCC isn't: http://sdcc.sourceforge.net/doc/sdccm...de172.html So, unfortunately, most of us do still have to create our own. :-( And instead of defines you could also use an enum. Please signal clearly before making an abrupt turn! Now we've changed the subject to using 'enum' instead of #define for the "magic numbers". Yes, you could certainly do it that way in both C99 and C89 [1] "C99" and "C89" refer to different versions of the so-called "ANSI" standard definition of the 'C' programming language - the "99" and "89" refer to the year of publication, so C99 is the more recent (in fact, the most recent?) See the sidebar, C-ninety-what?, on this page: http://www-128.ibm.com/developer...l-c99.html |
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 |