473,804 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Experiences using "register"

Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?
Mar 17 '08
65 2619
Richard Tobin wrote:
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrote:
>"An example of proper use:

for (register int i= 0; i < INT_MAX; ++i)
array[i] *= i;

Is there *any* C compiler out there that accepts this syntax but
has such a useless optimiser that using "register" is worthwhile?
A loop variable has to be the most obvious case where any
reasonable compiler will use a register anyway.
I seriously doubt that example. If any element of a[] is greater
than 1 it will cause overflow, and un or implementation defined
action.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 30 '08 #31
CBFalconer wrote:
Richard Tobin wrote:
>Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrote:
>>"An example of proper use:

for (register int i= 0; i < INT_MAX; ++i)
array[i] *= i;
Is there *any* C compiler out there that accepts this syntax but
has such a useless optimiser that using "register" is worthwhile?
A loop variable has to be the most obvious case where any
reasonable compiler will use a register anyway.

I seriously doubt that example. If any element of a[] is greater
than 1 it will cause overflow, and un or implementation defined
action.

Consider sizeof(array)/sizeof(*array)= = INT_MAX and the elements of the
array being 1s and 0s.

Mar 30 '08 #32
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
CBFalconer wrote:
>Richard Tobin wrote:
>>Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrote:

"An example of proper use:

for (register int i= 0; i < INT_MAX; ++i)
array[i] *= i;
Is there *any* C compiler out there that accepts this syntax but
has such a useless optimiser that using "register" is worthwhile?
A loop variable has to be the most obvious case where any
reasonable compiler will use a register anyway.

I seriously doubt that example. If any element of a[] is greater
than 1 it will cause overflow, and un or implementation defined
action.


Consider sizeof(array)/sizeof(*array)= = INT_MAX and the elements of the
array being 1s and 0s.
Don't worry, you're just witnessing the wondrous Chuck being obstructive
and pedantic as usual. Everyone else knew what you were driving at.

Mar 30 '08 #33
Richard wrote:
>If the function is more than 5-6 lines of code, "register" should not be
used for the function scope but only for local scopes in the function
(like small loops).

Where do you get these "facts" that you maintain are true with zero to
back them up? It all depends on the compiler and also depend, in a
larger function, on how often your register variable was used and how it
was used. Length in lines has absolutely nothing to do with it.

The smaller the scope, the less effect it has on the rest of code. Where
do you disagree with this?
Mar 30 '08 #34
Ioannis wrote:
) Richard wrote:
)>If the function is more than 5-6 lines of code, "register" should not be
)>used for the function scope but only for local scopes in the function
)>(like small loops).
)>
)Where do you get these "facts" that you maintain are true with zero to
)back them up? It all depends on the compiler and also depend, in a
)larger function, on how often your register variable was used and how it
)was used. Length in lines has absolutely nothing to do with it.
)
) The smaller the scope, the less effect it has on the rest of code. Where
) do you disagree with this?

You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the code ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Mar 30 '08 #35
Willem wrote:
Ioannis wrote:
) Richard wrote:
)>If the function is more than 5-6 lines of code, "register" should not be
)>used for the function scope but only for local scopes in the function
)>(like small loops).
)>
)Where do you get these "facts" that you maintain are true with zero to
)back them up? It all depends on the compiler and also depend, in a
)larger function, on how often your register variable was used and how it
)was used. Length in lines has absolutely nothing to do with it.
)
) The smaller the scope, the less effect it has on the rest of code. Where
) do you disagree with this?

You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the code ?

Why "inline" should be used with small functions only?
Mar 30 '08 #36
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
Willem wrote:
>Ioannis wrote:
) Richard wrote:
)>If the function is more than 5-6 lines of code, "register" should not be
)>used for the function scope but only for local scopes in the function
)>(like small loops).
)>
)Where do you get these "facts" that you maintain are true with zero to
)back them up? It all depends on the compiler and also depend, in a
)larger function, on how often your register variable was used and how it
)was used. Length in lines has absolutely nothing to do with it.
)
) The smaller the scope, the less effect it has on the rest of code. Where
) do you disagree with this?

You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the code ?


Why "inline" should be used with small functions only?
Because it adversely affects code size is one thing I can think of ...

Mar 30 '08 #37
Richard wrote:
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
>Willem wrote:
>>Ioannis wrote:
) Richard wrote:
)>If the function is more than 5-6 lines of code, "register" should not be
)>used for the function scope but only for local scopes in the function
)>(like small loops).
)>
)Where do you get these "facts" that you maintain are true with zero to
)back them up? It all depends on the compiler and also depend, in a
)larger function, on how often your register variable was used and how it
)was used. Length in lines has absolutely nothing to do with it.
)
) The smaller the scope, the less effect it has on the rest of code. Where
) do you disagree with this?

You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the code ?

Why "inline" should be used with small functions only?

Because it adversely affects code size is one thing I can think of ...

Exactly. "register" should be used in as a small scope as possible, so
as it affects (or better: doesn't affect) code that is not intended to
be affected.

Mar 30 '08 #38
Corrected:

Ioannis Vranos wrote:
Richard wrote:
>Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
>>Willem wrote:
Ioannis wrote:
) Richard wrote:
)>If the function is more than 5-6 lines of code, "register" should not be
)>used for the function scope but only for local scopes in the function
)>(like small loops).
)>
)Where do you get these "facts" that you maintain are true with zero to
)back them up? It all depends on the compiler and also depend, in a
)larger function, on how often your register variable was used and how it
)was used. Length in lines has absolutely nothing to do with it.
)
) The smaller the scope, the less effect it has on the rest of code. Where
) do you disagree with this?

You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the code ?
Why "inline" should be used with small functions only?
Because it adversely affects code size is one thing I can think of ...

Exactly. "register" should be used in as a small scope as possible, so
as it doesn't affect code that is not intended to be affected.

Mar 30 '08 #39
On Sun, 30 Mar 2008 16:55:58 +0200, Richard wrote:
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
>Willem wrote:
>>You're arguing in circles again.
Why should 'register' be used only when it has minimal effect on the
code ?

Why "inline" should be used with small functions only?

Because it adversely affects code size is one thing I can think of ...
If the function is huge, but it's only called from one place, inlining
may even decrease the code size.
Mar 30 '08 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.