size of byte

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

size of byte

8,746 Views
Bud
Contributor I
I am attempting to install another persons files into my portion of the project.
 
He has defined the following 2 sections of code.
 
Section 1 compiles properly
 
section 2 has a problem.
 
I have included the #define statements also.
 
What I think is happening is that the compiler has a problem fitting the high 8 bit define values into the 8 bit byte space since there is no problem with the lower 8 bits.
 
Any ideas/comments?
Bud
 
#defines
#define Bit0  (0x0001)
#define Bit1  (0x0002)
#define Bit2  (0x0004)
#define Bit3  (0x0008)
#define Bit4  (0x0010)
#define Bit5  (0x0020)
#define Bit6  (0x0040)
#define Bit7  (0x0080)
#define Bit8  (0x0100)
#define Bit9  (0x0200)
#define Bit10 (0x0400)
#define Bit11 (0x0800)
#define Bit12 (0x1000)
#define Bit13 (0x2000)
#define Bit14 (0x4000)
#define Bit15 (0x8000)
section 1
/*** DBGCAL - Debug Comparator A Low Register; 0x00001811 ***/
typedef union {
  byte Byte;
  struct {
    byte Bit0        :1;                                       /* Debug Comparator A Bit 0 */
    byte Bit1        :1;                                       /* Debug Comparator A Bit 1 */
    byte Bit2        :1;                                       /* Debug Comparator A Bit 2 */
    byte Bit3        :1;                                       /* Debug Comparator A Bit 3 */
    byte Bit4        :1;                                       /* Debug Comparator A Bit 4 */
    byte Bit5        :1;                                       /* Debug Comparator A Bit 5 */
    byte Bit6        :1;                                       /* Debug Comparator A Bit 6 */
    byte Bit7        :1;                                       /* Debug Comparator A Bit 7 */
  } Bits;
} DBGCALSTR;
section 2
/*** DBGCAH - Debug Comparator A High Register; 0x00001810 ***/
typedef union {
  byte Byte;
  struct {
    byte Bit8        :1;                                       /* Debug Comparator A Bit 8 */
    byte Bit9        :1;                                       /* Debug Comparator A Bit 9 */
    byte Bit10       :1;                                       /* Debug Comparator A Bit 10 */
    byte Bit11       :1;                                       /* Debug Comparator A Bit 11 */
    byte Bit12       :1;                                       /* Debug Comparator A Bit 12 */
    byte Bit13       :1;                                       /* Debug Comparator A Bit 13 */
    byte Bit14       :1;                                       /* Debug Comparator A Bit 14 */
    byte Bit15       :1;                                       /* Debug Comparator A Bit 15 */
  } Bits;
} DBGCAHSTR;
 
The error message is
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3307  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3308  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3308  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3308  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3309  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3309  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3309  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3310  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3310  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3310  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3311  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3311  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3311  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3312  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3312  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3312  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3313  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3313  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3313  
Error   : C1008: Typedef name expected
MC9S08GT16.h line 3314  
Error   : C1007: Type specifier mismatch
MC9S08GT16.h line 3314  
Error   : C2450: Expected:  ~ ( IDENT 
MC9S08GT16.h line 3314  
Error   : Compile failed
Warning : C1420: Result of function-call is ignored
radio.c line 108  
Warning : C1420: Result of function-call is ignored
radio.c line 113  
Warning : C2705: Possible loss of data
radio.c line 559  
 
Labels (1)
0 Kudos
Reply
4 Replies

2,228 Views
CompilerGuru
NXP Employee
NXP Employee
The problem is a simple name collision one, it has nothing to do with the number of bits.
After preprocessing, the compiler sees:
..
typedef union {
byte Byte;
struct {
byte (0x0001) :1;
byte (0x0002) :1;
byte (0x0004) :1;
..
This is just not legal, whenever macros are used, checking the preprocessor is always a good idea.

In order to resolve this name collision, you could:
- use other names at one place (probably your macros, as macros are just more dangerous)
- use enums instead of macros for the numerical values (enum {Bit0=1,Bit1=2..
(this allows to keep the sources pretty much as they are)
- not using the two headers together


Daniel
0 Kudos
Reply

2,228 Views
bigmac
Specialist III

Hello Bud,

Strictly speaking, this post is in the wrong forum - the CW forum might be more appropriate to this type of query.

I suspect the errors are because you have defined values for Bit8 through to Bit15 that exceed the size of byte, whereas the size of Bit0 through to Bit7 do not.

I am not sure why the defines are there - since you seem to be following the pattern used by the Freescale derivative files, so I might have expected something similar to the following:

/*** DBGCAL - Debug Comparator A Low Register; 0x00001811 ***/
typedef union {
 byte Byte;
 struct {
   byte Bit0    :1;       /* Debug Comparator A Bit 0 */
   byte Bit1    :1;       /* Debug Comparator A Bit 1 */
   byte Bit2    :1;       /* Debug Comparator A Bit 2 */
   byte Bit3    :1;       /* Debug Comparator A Bit 3 */
   byte Bit4    :1;       /* Debug Comparator A Bit 4 */
   byte Bit5    :1;       /* Debug Comparator A Bit 5 */
   byte Bit6    :1;       /* Debug Comparator A Bit 6 */
   byte Bit7    :1;       /* Debug Comparator A Bit 7 */
 } Bits;
} DBGCALSTR;
extern volatile DBGCALSTR _DBGCAL @ 0x00001811;
 
/*** DBGCAH - Debug Comparator A High Register; 0x00001810 ***/
typedef union {
 byte Byte;
 struct {
   byte Bit8    :1;       /* Debug Comparator A Bit 8 */
   byte Bit9    :1;       /* Debug Comparator A Bit 9 */
   byte Bit10   :1;       /* Debug Comparator A Bit 10 */
   byte Bit11   :1;       /* Debug Comparator A Bit 11 */
   byte Bit12   :1;       /* Debug Comparator A Bit 12 */
   byte Bit13   :1;       /* Debug Comparator A Bit 13 */
   byte Bit14   :1;       /* Debug Comparator A Bit 14 */
   byte Bit15   :1;       /* Debug Comparator A Bit 15 */
 } Bits;
} DBGCAHSTR;
extern volatile DBGCAHSTR _DBGCAH @ 0x00001810;

The volatile would be necessary if a hardware register.  So you might then define
 
#define DBGCA_BIT8  _DBGCAH.Bits.Bit8
etc.
I presume this is what you are trying to achieve.
 
Regards,
Mac
 

 

Message Edited by bigmac on 2006-07-14 01:43 PM

0 Kudos
Reply

2,228 Views
Bud
Contributor I
Thanks for your response.  The code segment I posted was from another person.  You basically confirmed what I was believing that basically Bits should not be typed as a byte but more as a word.
 
Bud
0 Kudos
Reply

2,228 Views
bigmac
Specialist III
Hello Bud,


Bud wrote:
Thanks for your response.  The code segment I posted was from another person.  You basically confirmed what I was believing that basically Bits should not be typed as a byte but more as a word.
Bud

Not if you require to handle the bits within two separate bytes, as your code would indicate.  So Bit0 through to Bit7 would pertain to the byte register DBGCAL, and Bit8 through to Bit15 to the byte register DBGCAH.

I am not entirely sure what you are trying to achieve - my assumption was that you were aiming at the simplification of the handling of individual bits within the two single byte registers, by use of a name for each bit.

You appear to be trying to identify the individual bits as both a mask (per the defines) and also within the structure.  My understanding of this issue is that only one of the methods would be required.


Regards,
Mac

0 Kudos
Reply