Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/20/03 17:43
Read: times


 
#46150 - RE: bitfields
Responding to: ???'s previous message
This all has to do with cross-platform code portability. I work with many different architectures and tools. Macros of this sort are in a portdef.h (portability definitions) file that allows me to reuse code and hopefully not worry about the target architecture. Not all macros get used, just like not all library functions would get used when you include stdio.h. Another section of this file shows what a U16 is. This section also shows small difference between, for example, Keil C51 (8-bit), HI-TECH PICC (8-bit), Diab DCC (32-bit PowerPC), and MS VC++ (32-bit) compilers. With some 32-bit systems, you've got to worry about alignment faults, structure packing, etc.
/** Machine and/or Compiler Specifics
 *
 *  BIG_ENDIAN specifies the byte and word ordering convention.
 *  If TRUE (1), the target implementation is big-endian;
 *  otherwise, FALSE (0) means little-endian.
 *
 *  UNALIGNED_DATA_ACCESS_OK specifies whether unaligned data
 *  accesses are fault-free.  If TRUE (1), reading or writing an
 *  object that is not aligned on its natural boundary will not
 *  cause a fault (but could reduce performance); otherwise,
 *  FALSE (0) means that an unaligned access will cause a fault.
 *
 *  PRAGMA_PACK_ENABLE and PRAGMA_PACK_DISABLE are
 *  compiler-specific preprocessor tokens that control structure
 *  packing.
 *
 *  Note: The widths connoted byte these typedef's may not be
 *        exactly represented on some architectures (e.g., some
 *        DSP's have 24-bit integers).
 */
#if   defined (__C51__) /* Keil C51 */

typedef signed   char   S8;
typedef unsigned char   U8;
typedef signed   short  S16;
typedef unsigned short  U16;
typedef signed   long   S32;
typedef unsigned long   U32;

#define BIG_ENDIAN                  1   /**< Big-endian         */
#define PRAGMA_PACK_ENABLE
#define PRAGMA_PACK_DISABLE
#define UNALIGNED_DATA_ACCESS_OK    1   /**< Won't cause faults */

#elif defined (_MPC_)   /* HI-TECH PICC */

typedef signed   char   S8;
typedef unsigned char   U8;
typedef signed   short  S16;
typedef unsigned short  U16;
typedef signed   long   S32;
typedef unsigned long   U32;

#define BIG_ENDIAN                  0   /**< Little-endian      */
#define PRAGMA_PACK_ENABLE
#define PRAGMA_PACK_DISABLE
#define UNALIGNED_DATA_ACCESS_OK    1   /**< Won't cause faults */

#elif defined (__DCC__) /* Diab */

typedef signed   char   S8;
typedef unsigned char   U8;
typedef signed   short  S16;
typedef unsigned short  U16;
typedef signed   long   S32;
typedef unsigned long   U32;

#define BIG_ENDIAN                  1   /**< Big-endian         */
#define PRAGMA_PACK_ENABLE          pack
#define PRAGMA_PACK_DISABLE         pack()
#define UNALIGNED_DATA_ACCESS_OK    1   /**< Won't cause faults */

#else   /* Assume MS VC++ PC host compiler. */

/*  Replacements for C51 specific names/extensions.
 */
#define idata
#define xdata
#if 0
#define data
#define code
#endif
#define reentrant

/*  Replacements for PICC specific names/extensions.
 */
#define bank0
#define bank1
#define bank2
#define bank3

/*  Replacements for C51 and PICC specific names/extensions.
 */
#define bit                 U8

typedef signed   char       S8;
typedef unsigned char       U8;
typedef signed   short      S16;
typedef unsigned short      U16;
typedef signed   long       S32;
typedef unsigned long       U32;
typedef signed   __int64    S64;
typedef unsigned __int64    U64;

#define BIG_ENDIAN                  0   /**< Little-endian      */
#define PRAGMA_PACK_ENABLE          pack(1)
#define PRAGMA_PACK_DISABLE         pack()
#define UNALIGNED_DATA_ACCESS_OK    1   /**< Won't cause faults */



List of 15 messages in thread
TopicAuthorDate
bitfields            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
         RTFM!            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
         RE: bitfields            01/01/70 00:00      
            RE: bitfields            01/01/70 00:00      
               RE: bitfields            01/01/70 00:00      
                  RE: bitfields            01/01/70 00:00      
   See the Keil site.            01/01/70 00:00      
      RE: See the Keil site.            01/01/70 00:00      
         RE: See the Keil site.            01/01/70 00:00      

Back to Subject List