473,422 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

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 2513
Willem wrote:
)
) OK, we have a comprehension problem. Replace my phrase "as small a scope
) as possible" with "a small scope".

If you make that replacement, then suddenly your statement doesn't sound
so self-evident any more, as I already indicated.

So answer the question above: *WHY* should 'register' only be used
on small scopes ? If I use it on a large scope, then I *intend* that
it affects a lot of code. I see no reason why I shouldn't do that.

The intention of using "register" is per variable. Having "register"
used in small scopes you avoid unwanted side-effects on the rest of code
as mentioned by others.
Mar 30 '08 #51
Ioannis wrote:
) The intention of using "register" is per variable. Having "register"
) used in small scopes you avoid unwanted side-effects on the rest of code
) as mentioned by others.

That sounds like a 'rule of thumb', or like 'good practise'.

But this thread started with your mention of 'proper use'.
Are you saying that 'proper use' is the same as 'good practise',
and that any exception to the rule, no matter how appropriate
or intended, is not 'proper use' ?

For example, if a variable is heavily used throughout the function,
for several different purposes, I consider it a good idea to declare
that variable 'register'. For the entire function.
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 #52
Willem wrote:
Ioannis wrote:
) The intention of using "register" is per variable. Having "register"
) used in small scopes you avoid unwanted side-effects on the rest of code
) as mentioned by others.

That sounds like a 'rule of thumb', or like 'good practise'.

But this thread started with your mention of 'proper use'.
Are you saying that 'proper use' is the same as 'good practise',
and that any exception to the rule, no matter how appropriate
or intended, is not 'proper use' ?

For example, if a variable is heavily used throughout the function,
for several different purposes, I consider it a good idea to declare
that variable 'register'. For the entire function.

Yes, what I am saying about "register" and small scopes is a general
good practice.
Mar 30 '08 #53
Ioannis wrote:
) Yes, what I am saying about "register" and small scopes is a general
) good practice.

But are you saying that using "register" in small scopes
is the only 'proper use' ? And that using it in larger
scopes is therefore 'improper use' ?
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 #54
Willem wrote:
Ioannis wrote:
) Yes, what I am saying about "register" and small scopes is a general
) good practice.

But are you saying that using "register" in small scopes
is the only 'proper use' ? And that using it in larger
scopes is therefore 'improper use' ?

I am saying that using "register" in small scopes is a general good
practice when using this keyword, the same way as using "inline" with
small functions is a general good practice.
Naturally there are exceptions to these rules.

An exception example for "register" is when we want a specific portion
of code to run as fast as possible without caring about run-time
efficiency of the rest of the code because of this.

An exception example for "inline" is when we want a large function with
many calls to be called as fast as possible, without caring about space
efficiency.
Mar 30 '08 #55
Ioannis wrote:
) I am saying that using "register" in small scopes is a general good
) practice when using this keyword, the same way as using "inline" with
) small functions is a general good practice.
)
)
) Naturally there are exceptions to these rules.
)
) An exception example for "register" is when we want a specific portion
) of code to run as fast as possible without caring about run-time
) efficiency of the rest of the code because of this.

This whole thread started with the observation that a compiler should
be considered defective if it generates less-efficient code when the
"register" keyword is used 'properly'.

I guess we can put that discussion behind us then ?

) An exception example for "inline" is when we want a large function with
) many calls to be called as fast as possible, without caring about space
) efficiency.
By the way, most present day compilers will put small-scope variables
in registers, and make small functions inline automatically.

This leaves the specific 'register' and 'inline' keywords for those cases
that are exceptions to the rule, such as those with large functions and
large variable scopes.
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 #56
Richard wrote:
) Large functions are rarely called frequently enough to have the overhead
) of the call/return to have any noticeable impact.

Look crossthread for my explanation about how 'inline' gives the compiler
the opportunity for better optimization of the inlined function, because
it can use the information about the specific call. This is especially
evident when the function is called with constant arguments.
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 #57
Willem <wi****@stack.nlwrites:
Richard wrote:
) Large functions are rarely called frequently enough to have the overhead
) of the call/return to have any noticeable impact.

Look crossthread for my explanation about how 'inline' gives the compiler
the opportunity for better optimization of the inlined function, because
it can use the information about the specific call. This is especially
evident when the function is called with constant arguments.
SaSW, Willem
"rarely" would apply here too I suspect.
Mar 30 '08 #58
Richard wrote:
) Willem <wi****@stack.nlwrites:
)
)Richard wrote:
)) Large functions are rarely called frequently enough to have the overhead
)) of the call/return to have any noticeable impact.
)>
)Look crossthread for my explanation about how 'inline' gives the compiler
)the opportunity for better optimization of the inlined function, because
)it can use the information about the specific call. This is especially
)evident when the function is called with constant arguments.
)
) "rarely" would apply here too I suspect.

I simply pointed out that call overhead is not the only reason to
inline functions. I wouldn't even be surprised if most of the gains
from inlining on average uses are not because of the call overhead.
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 #59
On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam.no.spamfreemail.grwrote:
"register" is part of the language standard, if a compiler considers it
unneeded, it is free to ignore it. Proper uses of "register" making the
compiler to produce less-efficient code than not using it at all, is a
compiler-defect.
Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
keyword register with white space.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
Mar 31 '08 #60
Flash Gordon wrote:
Herbert Rosenau wrote, On 31/03/08 20:22:
>On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam.no.spamfreemail.grwrote:
>>"register" is part of the language standard, if a compiler considers it
unneeded, it is free to ignore it. Proper uses of "register" making the
compiler to produce less-efficient code than not using it at all, is a
compiler-defect.

Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
keyword register with white space.

Not quite. If you attempt to take the address of a register variable the
compiler is required to produce a diagnostic. Apart from that, just it
can ignore it.
Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.

--
Er*********@sun.com
Mar 31 '08 #61
Eric Sosman wrote:
Flash Gordon wrote:
>Herbert Rosenau wrote, On 31/03/08 20:22:
>>On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam.no.spamfreemail.grwrote:

"register" is part of the language standard, if a compiler considers it
unneeded, it is free to ignore it. Proper uses of "register" making the
compiler to produce less-efficient code than not using it at all, is a
compiler-defect.

Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
keyword register with white space.

Not quite. If you attempt to take the address of a register variable
the compiler is required to produce a diagnostic. Apart from that,
just it can ignore it.

Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.

Yes, in the second case, x is in file or global scope. What is your point?

Mar 31 '08 #62
Ioannis Vranos wrote, On 31/03/08 22:56:
Eric Sosman wrote:
>Flash Gordon wrote:
>>Herbert Rosenau wrote, On 31/03/08 20:22:
On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam.no.spamfreemail.grwrote:

"register" is part of the language standard, if a compiler considers it
unneeded, it is free to ignore it. Proper uses of "register" making the
compiler to produce less-efficient code than not using it at all, is a
compiler-defect.
Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
>>>keyword register with white space.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>Not quite. If you attempt to take the address of a register variable
the compiler is required to produce a diagnostic. Apart from that,
just it can ignore it.
Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.

Yes, in the second case, x is in file or global scope. What is your point?
The point is that what Herbert wrote was incorrect for at least two reasons.
--
Flash Gordon
Mar 31 '08 #63
Flash Gordon wrote:
Ioannis Vranos wrote, On 31/03/08 22:56:
>Eric Sosman wrote:
>>Flash Gordon wrote:
Herbert Rosenau wrote, On 31/03/08 20:22:
On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam.no.spamfreemail.grwrote:
>
>"register" is part of the language standard, if a compiler
>considers it
>unneeded, it is free to ignore it. Proper uses of "register"
>making the
>compiler to produce less-efficient code than not using it at all,
>is a
>compiler-defect.
Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
>>>>keyword register with white space.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>Not quite. If you attempt to take the address of a register variable
the compiler is required to produce a diagnostic. Apart from that,
just it can ignore it.
Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.

Yes, in the second case, x is in file or global scope. What is your
point?

The point is that what Herbert wrote was incorrect for at least two
reasons.

Ah right. You are probably referring to C95 implicit int. So in
C99/C++98 the above would be register int x= 47;
Mar 31 '08 #64
Ioannis Vranos <iv*****@nospam.no.spamfreemail.grwrites:
Flash Gordon wrote:
>Ioannis Vranos wrote, On 31/03/08 22:56:
>>Eric Sosman wrote:
Flash Gordon wrote:
Herbert Rosenau wrote, On 31/03/08 20:22:
[...]
>>>>>Yes, but since C98/99 its free to the compiler simply ignoring
>'register'. That means it is the right to the compiler to replace the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
>>>>>keyword register with white space.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>Not quite. If you attempt to take the address of a register variable
the compiler is required to produce a diagnostic. Apart from that,
just it can ignore it.
Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.

Yes, in the second case, x is in file or global scope. What is your
point?

The point is that what Herbert wrote was incorrect for at least two
reasons.

Ah right. You are probably referring to C95 implicit int. So in
C99/C++98 the above would be register int x= 47;
Well, in C99 it wouldn't exist, since the issue being illustrated
doesn't apply to C99.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 1 '08 #65
Ioannis Vranos wrote, On 01/04/08 00:20:
Flash Gordon wrote:
>Ioannis Vranos wrote, On 31/03/08 22:56:
>>Eric Sosman wrote:
Flash Gordon wrote:
Herbert Rosenau wrote, On 31/03/08 20:22:
>On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
><iv*****@nospam.no.spamfreemail.grwrote:
>>
>>"register" is part of the language standard, if a compiler
>>considers it
>>unneeded, it is free to ignore it. Proper uses of "register"
>>making the
>>compiler to produce less-efficient code than not using it at all,
>>is a
>>compiler-defect.
>Yes, but since C98/99 its free to the compiler simply ignoring
>'register'. That means it is the right to the compiler to replace the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
>>>>>keyword register with white space.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>>Not quite. If you attempt to take the address of a register variable
the compiler is required to produce a diagnostic. Apart from that,
just it can ignore it.
Another corner case:

int x = 42;

int f(void) {
register x = 27;
return x;
}

int g(void) {
/*register*/ x = 27;
return x;
}

The two functions do different things.
Yes, in the second case, x is in file or global scope. What is your
point?
The point is that what Herbert wrote was incorrect for at least two
reasons.

Ah right. You are probably referring to C95 implicit int. So in
C99/C++98 the above would be register int x= 47;
Eric was using implicit int and therefore not C99 but my point stands
for all versions of the standard.
register int i;
/*register*/ int j;
&i; /* diagnostic required */
&j; /* no diagnostic required */
--
Flash Gordon
Apr 1 '08 #66

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.