View Full Version : c storage duration


system_eyes
hello
concerning automatic storage duration , what is the differances
between {auto} and {register },
actually the book didn't explain it well .

MaherG
Register: Stores the variable in one of the registers, to lessen fetch cycles.

Auto: Allocates variable as soon as entering the block and deallocating it as soon as it exits. (Although thats what happens even w/o stating auto)

Hope this helps

Maher

safrout
i think u need to joina Forum for C support not linux support

and u may also google for other books online than urs which may explain the diff in a good way

sattia
As Maher stated specifying auto or not does not affect because all variables are auto by default unless explicity defined otherwise.
Note on register variables:
1 - u cannot use the & operator with them cause they dnt ve memory addresses
2 - number of register variables is limited because number of processor registers is limited to
3 - a register variable may be a register; defining a register variable means that it might be a register. They can be silently ignored by the compiler if no registers available.

mohamed
Originally posted by safrout
i think u need to joina Forum for C support not linux support

and u may also google for other books online than urs which may explain the diff in a good way

We are in Programming forum.

joe_lite
hi dear
as the perfect guys here said ,auto is not that important as it is the default
BUT NOTE
register only really is not important,Why?!!!
because it tell the compiler to "try to" allocate a register for that variable and not obliging it to find one ,AND as we have a very limited general purpose registers on our IA32 (only 4) then it,s more likely that the register allocator will neglect our request
dear.. the register keyword is a part of the ANSI C which does not expect a certain machine and as there is a huge number of processors have 32 or even 128 registers then this keyword invented but on the intel there is a small chance
and remember that push and pop from the stack is not a very expensive operation on IA32
bye
joe

MaherG
You should refer to register when you are improving your software efficiency.

Maher

safrout
Originally posted by mohamed


We are in Programming forum.


i think that this section is for solving problems which face anymember during building or debugging a program

not for teaching programming

uniball
Originally posted by safrout



i think that this section is for solving problems which face anymember during building or debugging a program

not for teaching programming
The forum description:

All about research and development, programming including Bash scripts, Python, Kylix, C++, Perl, PHP, etc.

safrout
OK

as u all wish but i insist on my point of view that if u need to learn programming go for a forum which is made basiclly for teaching programming

few days i ago i wanted to know what is the command which makes the programme made by C++ don't close itself after finishing the proccess it is making

i went and asked at the #C++ on freenode server

not here

cos i still see that here is only for developing and helping in programming a new programe or debugging one but not for learning


cos if u opened this door ( teaching PL) i think we won't be able to double the support this forum was made for

sure my words won't change anything and maybe noone will agree with me but thats how i think

excuse me

Salam

^3aFrEt^
helping in programming a new programe or debugging one but not for learning

what is the diffrence between helping in programming and learning ?:)

u help one = one learn more

bro it was only a small question as i see , we should encourage these questions