| Author |
Message |
saudrehman
Joined: 20 Dec 2005 Posts: 46 Helped: 1
|
16 Aug 2006 6:35 bit declaration |
|
|
|
|
Suppose i am using a 32 bit controller in which each memory location is 16 bits long.
if i declare an unsigned char variable of 8 bytes then how is it interpreted by compiler?
Does it have any meaning or by default it shall allocate 2 bytes?
|
|
| Back to top |
|
 |
Google AdSense

|
16 Aug 2006 6:35 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
jan noha
Joined: 10 Dec 2002 Posts: 32 Helped: 1
|
16 Aug 2006 20:26 8 bit declaration |
|
|
|
|
As far as I know, sizeof(char) == sizeof(unsigned char) == 1 Byte. It is directly stated somewhere in C language norm, where - if I remember it correctly - char/uchar is the only type defined by its size. (Another types are defined with the help of "<=" and/or "==".)
From it follows, that the maximum value in unsigned char is always 0xff (interpreted by the compiler), but it does not mean, that one char allocate 1 Bytes only, because usually all variables on 16/32bits systems are WORD/DWORD aligned and thus 1 Byte of data (char) is padded with some "unused space". It is not a rule, because it is a system dependent feature, but there is usually significant speed penalty, if the variable is not "correctly" aligned.
|
|
| Back to top |
|
 |
PaulHolland
Joined: 15 Jan 2003 Posts: 636 Helped: 59 Location: Holland
|
16 Aug 2006 20:53 Re: 8 bit declaration in 32 bit controllers |
|
|
|
|
Hi, if you type char you do not know. better use:
byte, or int8 if you can.
integer is not 16 bits but the normal word length on your cpu so 32 bits cpu has int of 32 bits !. if you want 32 bits on other platforms use long !!.
Paul.
|
|
| Back to top |
|
 |
RegUser_2
Joined: 24 Dec 2001 Posts: 235 Helped: 2
|
16 Aug 2006 23:43 Re: 8 bit declaration in 32 bit controllers |
|
|
|
|
Most controllers have possibility to access warious lenght words - that's why for instance instructions like mov.b , mow.w and mov.d exists.
Take a look at the assembler instruction of your controller to find out. Or complie with assembly output enable and take a look at the assembly listing.
|
|
| Back to top |
|
 |
swapgo
Joined: 24 Jun 2004 Posts: 127 Helped: 2
|
17 Aug 2006 11:35 Re: 8 bit declaration in 32 bit controllers |
|
|
|
|
Hi
Unsigned char will not contain 8 bytes. It contain just 8 bits ( might be typo error ) .
The compiler must take care by just allocating 8 bits.
Generally these type of info can be clearly found in the compiler user guide.
Regards
Gopi
|
|
| Back to top |
|
 |