473,796 Members | 2,462 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 2617
Flash Gordon wrote:
Herbert Rosenau wrote, On 31/03/08 20:22:
>On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospa m.no.spamfreema il.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*****@nosp am.no.spamfreem ail.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*****@nos pam.no.spamfree mail.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*****@no spam.no.spamfre email.grwrote:
>
>"registe r" is part of the language standard, if a compiler
>consider s 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.spamfreemai l.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_Keit h) <ks***@mib.or g>
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*****@n ospam.no.spamfr eemail.grwrote:
>>
>>"register " is part of the language standard, if a compiler
>>conside rs it
>>unneede d, it is free to ignore it. Proper uses of "register"
>>making the
>>compile r to produce less-efficient code than not using it at all,
>>is a
>>compile r-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.