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.

What is responsible for the space taken to store variables?

Status
Not open for further replies.

yahaa

Member level 1
Joined
Oct 9, 2005
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,566
the space taken to store variables of type integer, float etc depends on which factor?????
operating system???or compiler?????or computer architechture??????
if possible give an example
 

space for variables

Hi Yahaa,
I think its dependent on the compiler design. i am saying this because, compare the Turbo C & VC++ compilers... if a define a integer variable in a C program & compile it with both compilers seperately. you can see the deference. in Turbo C it allocates 2 words but in VC++ it allocates 4 words.

does anybody have any comments on this...

cheers...
 

space for variables

yahaa, are you asking about C, or some other language?

Yes, C integer sizes depend on the compiler, although the ANSI C standard specifies minimum number of integer bits, and floating point resolution (but not number of floating point bits). Refer to your header files limits.h, float.h, stdint.h.

char is at least 8 bits.
short int is at least 16 bits.
int is at least 16 bits.
long int is at least 32 bits.
long long int is at least 64 bits.
charbits <= shortintbits <= intbits <= longintbits <= longlongintbits.

The compiler authors usually choose integer and floating-point sizes that suit the CPU architecture and comply with the ANSI C standard. Turbo C dates back to the days of 16-bit CPUs such as 8086 and 80286, so it uses 16-bit int. Most hardware floating point units comply with IEEE Std 754, so we see a lot of 32-bit floats and 64-bit doubles.
 

space for variables

you can usually safely assume that a char is 1 byte, a short in 2 bytes, a long is 4 bytes, and long long (c99) is 8 bytes.
however, the size of int depends on the target processor. it's the same size of processor registers.
floats are 32-bits. however, depending on architecture, you can see 64-bits, 80-bits, 128-bits extended versions of floating points, under names double and long double.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top