register variable

M

macluvitch

Hello folks

I often use register variables within functions (or as funcion parameters)
that reauired speed like searching for example . I know that it doesn't
mean that every register variable will be holded in register

so is there any rules to precize when using them
thanks
 
C

Christopher Benson-Manica

macluvitch said:
I often use register variables within functions (or as funcion parameters)
that reauired speed like searching for example . I know that it doesn't
mean that every register variable will be holded in register

Short answer: You're probably wasting your time, at best.

Long answer: Look a few threads down for the latest discussion of the
register keyword.
 
J

J. J. Farrell

macluvitch said:
Hello folks

I often use register variables within functions (or as funcion parameters)
that reauired speed like searching for example . I know that it doesn't
mean that every register variable will be holded in register

so is there any rules to precize when using them

Yes - use them only when you want to prevent the code taking the address
of the variable.
 
A

Arthur J. O'Dwyer


You've just posted three messages in a row like this: no context,
no content (at least, not in English). Consider forming a coherent
sentence or two. Make sure your readers know what you're talking
about. Quote context if it's necessary to your point. Google
"Usenet FAQ" if you don't know how to post to newsgroups; it's worth
your while.

FWIW, the '?' operator in C has nothing to do with the 'register'
keyword.

-Arthur
 
O

Old Wolf

Yes - use them only when you want to prevent the code taking the address
of the variable.

The register keyword does not prevent code taking the address of the
variable. It is only an optimisation hint.
 
M

Martin Ambuhl

Old said:
The register keyword does not prevent code taking the address of the
variable. It is only an optimisation hint.

You are mistaken. Notice the word "Constraints."

6.5.3.2 Address and indirection operators

Constraints

The operand of the unary & operator shall be either a
function designator, the result of a [] or unary * operator,
or an lvalue that designates an object that is not a bit-
field and is not declared with the register storage-class
specifier.
 
J

Joona I Palaste

The register keyword does not prevent code taking the address of the
variable. It is only an optimisation hint.

If it didn't prevent code from taking the address of the variable, then
how would the compiler ever manage to optimise code that does take the
address of the variable?
 
J

J. J. Farrell

Old Wolf said:
The register keyword does not prevent code taking the address of the
variable. It is only an optimisation hint.

Tell that to the Standard.
 
O

Old Wolf

Martin Ambuhl said:
Old said:
The register keyword does not prevent code taking the address of the
variable. It is only an optimisation hint.

You are mistaken.>
The operand of the unary & operator shall be either a
function designator, the result of a [] or unary * operator,
or an lvalue that designates an object that is not a bit-
field and is not declared with the register storage-class
specifier.

ACK. I should know by now not to go by what some compilers (even in
strict c99 mode) will accept.
 
M

macluvitch

Sorry teacher :)
I meant by ie: ? (For example)
A coherent example that shows the use of a register variable
did u anderstand ?
 
M

Mark McIntyre

Sorry teacher :)
I meant by ie: ? (For example)
A coherent example that shows the use of a register variable

Perhaps there isn't one, in these days of optimising compilers.
did u anderstand ?

if you wrote in less opaque english, people might find it easier to
understand. For instance and stating what you want instead of using
abbreviations and hoping everyone can read your mind. I'm not being funny,
but most people here have busy lives and don't have time to second-guess
the true intentions of newbies.
 
R

Rich Gibbs

macluvitch said the following, on 05/06/04 09:22:
Sorry teacher :)
I meant by ie: ? (For example)
A coherent example that shows the use of a register variable
did u anderstand ?

Well, you are writing not only cryptically, but also incorrectly. The
abbreviation, "i.e.", is for Latin "id est", or "that is" in English.

The equivalent "for example" abbreviation is "e.g.", for Latin "exempli
gratia" (for [the sake of] example).

If you want someone to answer your questions, it is in your interest not
to write in riddles. Besides, how difficult is it to write, "Could you
please give an example?"
 
K

Keith Thompson

macluvitch said:
Sorry teacher :)
I meant by ie: ? (For example)
A coherent example that shows the use of a register variable
did u anderstand ?

This was in response to something posted about 4 days ago. You can't
reasonably expect us to remember the context. It's seldom necessary
to quote the entire article to which you're responding (unless it's
fairly short), but it's very helpful to provide *some* context.

(Incidentally, "i.e." means "that is" (Latin "id est"); "e.g." means
"for example" (Latin "exempli gratia").)

This is an international forum. We do use some jargon here, but
you'll find it much easier to communicate if you write in complete
words and complete sentences. The use of 'u' rather than 'you' is
particularly frowned upon, for reasons I won't get into.

In response to what I think your actual question was, there's probably
no good use these days for register variables. The original intent of
the "register" keyword was to provide a hint to the compiler that a
given variable is going to be used heavily, and that it would be
beneficial to store it in a CPU register rather than in main memory
(and that its address will never be taken). Modern compilers are
likely to be able to figure this out for themselves; you'll get a much
better performance improvement by adding "-O3" or equivalent to your
compiler's command line than by tweaking the source. The common
wisdom is that adding "register" keywords is more likely to hinder the
compiler's optimization than to help it; I don't know how accurate
that is.
 
M

macluvitch

since this moment I'll write
Thank you all folks rather than this cryptic one
Tanq u AlL Fallcks :)

Sorry for all troubles here
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top