Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8 bit declaration in 32 bit controllers

Status
Not open for further replies.

saudrehman

Member level 1
Joined
Dec 20, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,697
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?
 

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.
 

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.
 

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.
 

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top