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.

size of short and size of char in 8 bit machine

Status
Not open for further replies.

dhanraj_kmr

Advanced Member level 4
Joined
Sep 23, 2008
Messages
117
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Chennai, INDIA
Activity points
2,174
Dear All,
A basic question,
In a 8-bit machine,
sizeof(char) = 1 Bytes
sizeof(short) = 1 Bytes
sizeof(int) = 2 Bytes
sizeof(long) = 4 Bytes

if sizeof(char) = sizeof(short) = 1 Bytes means, why two different datatypes available? Why not only one?

Size varies when go for higher bits machine. Is this for code porting?

Regards,
Dhanaraj.S
 

It's only a convention.
Normally char represents ASCII value of a characters; 65 means A, 97 means a. If you asked your program to print 65 of char, it will convert to ASCII and print A. So you are prohibited to do mathematical calculation on char since it is considered as a character.

short represent numerical values, if you store 65 (ie. 01000001 in binary) is consider as a value and you are allowed to do calculation on it.
 

often one of the first tasks when using a new machine or compiler is to run a simple C program with prints the sizeof data types as the C and C++ standards only specify minimum sizes
https://www.cplusplus.com/doc/tutorial/variables/

problems can occur as you port code (e.g. from a systems where int is 32-bit to where it is 16-bit and one has loss of precision) or transferring binary information between systems (one can also have the problem of little endian and bit endian data storage)
 

the C and C++ standards only specify minimum sizes
And these minimum sizes (e.g. "short not smaller than 16 Bit") are often ignored by embedded compilers. Most compilers agree on char size of 8 bit.

Portable software projects mostly have their own unique type definitions, e.g. _unit16, _int32 or _sint32, they are typedefed in a processor and compiler specific include file.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top