Hey
I looking through some code, where the type of a parameter in a function call is stated as unsigned.
The data type (char, int, long) is not stated. Does any one know which type is assumed when not stated.
Use a [fairly] standard typedef for declarations and make notes within that file if the processor has restrictions...
/*--------------------------------------------------------------------------. ; declare my own typedeefs of the standard data types ; '--------------------------------------------------------------------------*/ typedef unsigned char u8; // CAUTION 16-bit only machine ... etc. typedef signed char s8; // CAUTION 16-bit only machine ... etc. typedef unsigned int u16; typedef signed int s16; typedef unsigned long u32; typedef signed long s32; typedef float f32; /*----------------------------------------------------------------------. ; if so desired, the volatile data-type is defined ; '----------------------------------------------------------------------*/ typedef volatile unsigned char vu8; // CAUTION 16-bit only machine ... etc. typedef volatile signed char vs8; // CAUTION 16-bit only machine ... etc. typedef volatile unsigned int vu16; typedef volatile signed int vs16; typedef volatile unsigned long vu32; typedef volatile signed long vs32; typedef volatile float vf32;
And then it becomes rather simple to know the sign and bit-width.
--Cpt. Vince Foster 2nd Cannon Place Fort Marcy Park, VA
No! Don't rely on notes - code monkeys will miss them!
Use conditional compilation to ensure that it's right!
#if defined COMPILER_A // Definitions for Compiler 'A' typedef unsigned char u8; typedef signed char s8; typedef unsigned int u16; typedef signed int s16; typedef unsigned long u32; typedef signed long s32; typedef float f32; #elif defined COMPILER_B // Definitions for Compiler 'B' typedef unsigned char u8; typedef signed char s8; typedef unsigned short u16; typedef signed short s16; typedef unsigned int u32; typedef signed int s32; typedef float f32; #else #error Unknown Compiler! #endif
Or
#if defined COMPILER_A #include "compiler_a.h" #elif defined COMPILER_B #include "compiler_b.h" #else #error Unknown Compiler! #endif
Although, if you're just starting now, it'd make sense to use the C99 standard names rather than u8, s16, etc...
Any, I understand that. It's not a 'bad' way to go, especially since code-monkeys have... uhm, lethologically challened at the moment... uhm, "issues."
I'm just not fond of conditional compilation. I think that this particular conditional compilation would be worth the effort if incorporated properly.
I would limit the conditional to e.g. #ifndef KeilC51 wrong definitions, make your own #endif
that keeps the clutter down.
and the "make your own" should scare a code monkey to quit
BTW Vince, I, personally, prefer U8 to u8 ....
Erik
Hmmmm, I use ALL_CAPITAL_LETTERS for #defines.
Granted a typedef is a form of #define, but I, personally, prefer u8 as opposed to U8.
(After checking, my editor [CodeWright v7.5] recognizes U8 as a typedef, whereas my code does not identify U8 as being typedef'd. Thanks for helping me catch that).