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
 

sinu_gowde

Full Member level 2
Joined
Nov 10, 2005
Messages
137
Helped
32
Reputation
64
Reaction score
12
Trophy points
1,298
Activity points
3,488
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...
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
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.
 

fdarkangel

Newbie level 6
Joined
Dec 2, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,398
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top