473,241 Members | 1,797 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,241 software developers and data experts.

What's the differences between REGISTER and AUTO?

Look the subject,that's my problem!
I hope someone can help me, thanks
Nov 4 '08 #1
21 6281
JOYCE wrote:
Look the subject,that's my problem!
Putting the question in the subject line is a problem. You should state
the full question in the body of your message; the subject line should,
at most, contain a summary of the question, not the question itself.
I hope someone can help me, thanks
Before asking us, what have you figured out for yourself from reading
your textbook? If you can't understand your text book, you're not likely
to understand the responses given in this newsgroup any better. However,
if you explain what you're having difficulty understanding from your
textbook's explanation, we can help correct your understanding.

Final note: C is a case-sensitive language. Make sure, whenever you
write down C identifiers, that you always write them in the correct
case. The identifier "register" is a keyword with a very specific
meaning defined by the standard. On the other hand "REGISTER" is a
completely unrelated identifier, which can only be declared or defined
in user code.
Nov 4 '08 #2
JOYCE wrote, On 04/11/08 11:58:
Look the subject,that's my problem!
It is better to put the entire question in the body of the post.
I hope someone can help me, thanks
What does your text book say? What is the difference between a car and a
road? Anyway, register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.

Another hint is that many processors have registers but I'm not aware of
any that have autos.
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 4 '08 #3
always leave the subject in the body of your message:

Subject: What's the differences between REGISTER and AUTO?

On 4 Nov, 11:58, JOYCE <zzzzzz90...@126.comwrote:
Look the subject,that's my problem!
I hope someone can help me, thanks
C is case sensitive so you mean auto and register.
They are both somewhat obselete and hardly ever used.

auto is used with variables to indicate they are not static
or external. That they are local to a function and are
(conceptually) created on entry and (conceptually) destroyed
on exit. A stack is often used to implement this.

int fred (void)
{
auto int i;
auto j
}

the above are both legal. j is implicitly int (at least in the 1989
standard for C).

Note this is completly unecessary. Just use

int i;
int j;

register indicates to the C compiler that the indicated variable
is heavily used (in the programmer's opinion) and should be placed
in a hardware register for faster code. You cannot take the address
of a register variable.

int bill (void)
{
register int i;
int *pi;
pi = &i; /* ILLEGAL *?
}

register is only a request to the compiler and the compiler is
permitted
to ignore it. For instance there may not actually be any spare
registers.
Programmers are often not good at correctly identifying the important
variables and modern compilers are good at it. Hence modern compilers
used ignore the "register" hint (except for disallowing taking the
address
of a register variable).

In <large-numyears of C programming I have never used either
register or auto. I've worked with code with register in it.
I've no idea if the register keyword did any good (or any harm).
I have only seen in auto in old books (I think K&R-one might use
it).
--
Nick Keighley


Nov 4 '08 #4
On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
JOYCE wrote, On 04/11/08 11:58:
[what is the difference between register and auto]
register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.
auto was still present in the 89 standard

--
Nick Keighley
Nov 4 '08 #5
Nick Keighley wrote:
On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
>JOYCE wrote, On 04/11/08 11:58:

[what is the difference between register and auto]
>register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.

auto was still present in the 89 standard
Present but not needed.

--
'Don't be afraid: /Electra City/
there will be minimal destruction.' - Panic Room

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Nov 4 '08 #6
JOYCE wrote:
Look the subject,that's my problem!
What subject? You didn't ask a question in your message. The question
you asked in your Subject line (which many people can't see when they
open your post) refers to REGISTER and AUTO, which are not defined by
ISO C; remember, C is case sensitive. I can see why you're having problems.
I hope someone can help me, thanks
If you meant to ask what the difference is between "register" and
"auto", the only guaranteed difference is that you cannot take the
address of a variable of "register" storage class with the unary & operator.

In ancient compilers, there was a chance that "register" variables might
have been faster to use, but modern optimizing compilers will
automatically put variables in registers without needing a hint from the
programmer.

S
Nov 4 '08 #7
Nick Keighley <ni******************@hotmail.comwrites:
On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
>JOYCE wrote, On 04/11/08 11:58:

[what is the difference between register and auto]
>register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.

auto was still present in the 89 standard
auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 4 '08 #8
Keith Thompson <ks***@mib.orgwrites:
Nick Keighley <ni******************@hotmail.comwrites:
>On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
>>JOYCE wrote, On 04/11/08 11:58:

[what is the difference between register and auto]
>>register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.

auto was still present in the 89 standard

auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.
Was there ever a time when `auto' did something useful?

It seems to have been redundant even in K&R I. Was it just included for
consistency, so that every storage class had a corresponding keyword?
It could maybe be useful to emphasize that a particular variable was
auto, where the context might suggest something else, but I can't really
think of a good example, and in any case a comment would probably be
just as good.
Nov 4 '08 #9
Nate Eldredge <na**@vulcan.lanwrites:
Keith Thompson <ks***@mib.orgwrites:
[...]
>auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.

Was there ever a time when `auto' did something useful?
Yes. Pre-ANSI C allowed implicit int for object declarations, so
"auto i;" was equivalent to "auto int i;", but "i;" was illegal (if it
appeared before a declaration in the same block) or a reference to a
variable ``i''.

In K&R C, one might write:

foo(x, y)
{
auto i;
extern j;
/* ... */
}

I *think* that "auto i;" is illegal in C90.

[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 4 '08 #10
Nate Eldredge <na**@vulcan.lanwrites:
Keith Thompson <ks***@mib.orgwrites:
>Nick Keighley <ni******************@hotmail.comwrites:
>>On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
JOYCE wrote, On 04/11/08 11:58:

[what is the difference between register and auto]

register is a hint to the compiler (which normally is not
needed and has not been needed for many years) which affects what you
can do with a variable, auto has not been needed as part of the language
for even longer since where it is legal the variable would have
automatic storage duration without using it.

auto was still present in the 89 standard

auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.

Was there ever a time when `auto' did something useful?

It seems to have been redundant even in K&R I.
Well, it is more a case of not wanting to remove it, I imagine. auto
comes from B, which is typeless, so the storage class must always be
there. As C evolved, the shadow of B remained in the guise of
implicit int:

auto x;

and

register y;

were ints just like

f() {...}

was an int-returning function. I imagine that for a while (pre-K&R I)
a lot of very early C looked a lot like B, except where the type
really mattered and then, after a while, it just seemed churlish to
remove the keyword. That last bit is a guess of course!

--
Ben.
Nov 4 '08 #11
Keith Thompson <ks***@mib.orgwrites:
Nate Eldredge <na**@vulcan.lanwrites:
>Keith Thompson <ks***@mib.orgwrites:
[...]
>>auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.

Was there ever a time when `auto' did something useful?

Yes. Pre-ANSI C allowed implicit int for object declarations, so
"auto i;" was equivalent to "auto int i;", but "i;" was illegal (if it
appeared before a declaration in the same block) or a reference to a
variable ``i''.

In K&R C, one might write:

foo(x, y)
{
auto i;
extern j;
/* ... */
}
I see.

In a sense, it's still redundant, because writing `int i;' would be
equivalent. But I can see how that wouldn't fit the idiom.
Nov 4 '08 #12
Keith Thompson wrote, On 04/11/08 16:58:
Nate Eldredge <na**@vulcan.lanwrites:
>Keith Thompson <ks***@mib.orgwrites:
[...]
>>auto is still in C99 as well; it's in the language, but either illegal
or redundant in all contexts. There's a proposal to drop it.
Was there ever a time when `auto' did something useful?

Yes. Pre-ANSI C allowed implicit int for object declarations, so
"auto i;" was equivalent to "auto int i;", but "i;" was illegal (if it
appeared before a declaration in the same block) or a reference to a
variable ``i''.

In K&R C, one might write:

foo(x, y)
{
auto i;
extern j;
/* ... */
}

I *think* that "auto i;" is illegal in C90.
C90 still had implicit int so I think that "auto i;" is legal in C90.
For what it's worth, gcc agrees with me and accepts it without complaint
with "-ansi -pedantic", you have to enable additional warnings or
(partial) C99 to get a warning.

I still don't think auto was useful in K&R C since one could always have
used "int i;" instead of "auto i;" with the same effect. Perhaps pre-K&R
there was a situation where nothing other than auto would do?
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 4 '08 #13
Nick Keighley wrote, On 04/11/08 13:08:

<snip>
auto is used with variables to indicate they are not static
or external. That they are local to a function and are
Local to the block, which can be a smaller scope than the entire function.
(conceptually) created on entry and (conceptually) destroyed
on exit. A stack is often used to implement this.

int fred (void)
{
auto int i;
auto j
Missing semi-colon ;-)
}

the above are both legal. j is implicitly int (at least in the 1989
standard for C).
Illegal in C99 of course.

<snip good stuff>
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 4 '08 #14
Flash Gordon wrote:
I still don't think auto was useful in K&R C since one could always have
used "int i;" instead of "auto i;" with the same effect. Perhaps pre-K&R
there was a situation where nothing other than auto would do?
Remember that it was a very gradual evolution from B to NB to C. When
language features were added (on a weekly basis, as K&R found something
new that would make coding easier), it was desirable that old code still
compile correctly so that they wouldn't have to constantly rewrite
existing programs that worked just fine; only new programs that needed
those new features (like types) had to use them.

B was typeless and so "auto i;" was the only way to declare a local
variable. For B programs to be valid C, it was necessary that C have
implicit int, meaning that "auto i;" was legal in C as well.

C99 started removing some of the old compatibility features because the
amount of code that still relied on it had become insignificant and had
become a source of bugs, programmer confusion, and unnecessary compiler
complexity. B is finally dead.

S
Nov 4 '08 #15
On Tue, 04 Nov 2008 08:38:25 -0600, Stephen Sprunk
<st*****@sprunk.orgwrote in comp.lang.c:
JOYCE wrote:
Look the subject,that's my problem!

What subject? You didn't ask a question in your message. The question
you asked in your Subject line (which many people can't see when they
open your post) refers to REGISTER and AUTO, which are not defined by
ISO C; remember, C is case sensitive. I can see why you're having problems.
I hope someone can help me, thanks

If you meant to ask what the difference is between "register" and
"auto", the only guaranteed difference is that you cannot take the
address of a variable of "register" storage class with the unary & operator.

In ancient compilers, there was a chance that "register" variables might
have been faster to use, but modern optimizing compilers will
automatically put variables in registers without needing a hint from the
programmer.
Of course your generalization above is not universally true.

That is the case for all generalizations, including this one.

I have yet to see a compiler whose output I could not improve with
judicious use of the register keyword when I needed to make the
effort, generally in time-critical real time code.

The programmer can often know things from the design of the code that
a compiler cannot discern without emulation or profiling of the entire
program.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Nov 5 '08 #16
"Nick Keighley" <ni******************@hotmail.comwrote in message
news:84961d20-3c81-4bd0-b5e6-
register is only a request to the compiler and the compiler is
permitted to ignore it. For instance there may not actually be
any spare registers.
I've worked with compilers where "register" was interpreted, as you
indicated, that this variable will have heavy use and, thus, it optimized
access to it even when it wasn't stored in a register.
In <large-numyears of C programming I have never used either
register or auto. I've worked with code with register in it.
It's still pretty popular in embedded programming, and many compilers used
for those targets will even spell out how many register variables will be
honored.
I've no idea if the register keyword did any good (or any harm).
Depends on the machine, of course. And yeah, I've seen places where it did
do harm. Usually because (as you also indicated) the programmer could be
wrong about what's really heavily used. In the cases I have in mind, he
specified several register variables, the compiler honored them, but as a
result it cut it's pool of registers for it's own optimizations and the code
got both fatter and slower.

- Bill

Nov 5 '08 #17
Jack Klein wrote:
>
The programmer can often know things from the design of the code that
a compiler cannot discern without emulation or profiling of the entire
program.
Modern hosted compilers can use profile feedback to tune optimisations.
I haven't come across an embedded compilers that do this, but I expect
there are those that do.

--
Ian Collins
Nov 5 '08 #18
Ian Collins <ia******@hotmail.comwrites:
Jack Klein wrote:
>>
The programmer can often know things from the design of the code that
a compiler cannot discern without emulation or profiling of the entire
program.

Modern hosted compilers can use profile feedback to tune optimisations.
I haven't come across an embedded compilers that do this, but I expect
there are those that do.
Haven't you come across GCC as an embedded compiler? I know at Freescale
all ARM- and POWER- targetted C was compiled using GCC. (OK, the DSPs and
PICs had other compilers, obviously.)

Phil
--
We must respect the other fellow's religion, but only in the sense and to the
extent that we respect his theory that his wife is beautiful and his children
smart. -- Henry Louis Mencken (1880-1956), American editor and critic
Nov 5 '08 #19
Nick Keighley wrote:
On 4 Nov, 12:51, Flash Gordon <s...@spam.causeway.comwrote:
auto was still present in the 89 standard
As well as the current C standard.

The thing that is interesting to me is that the specifier auto appears to
have no semantics in the Standard, except for preventing a declaration from
also having a typedef, static, extern, or register storage class specifier.

There is mention of automatic storage duration, but no explicit connection
to the auto storage class specifier.

--
Thad
Nov 6 '08 #20
Phil Carmody wrote:
Ian Collins <ia******@hotmail.comwrites:
>Jack Klein wrote:
>>The programmer can often know things from the design of the code that
a compiler cannot discern without emulation or profiling of the entire
program.
Modern hosted compilers can use profile feedback to tune optimisations.
I haven't come across an embedded compilers that do this, but I expect
there are those that do.

Haven't you come across GCC as an embedded compiler? I know at Freescale
all ARM- and POWER- targetted C was compiled using GCC. (OK, the DSPs and
PICs had other compilers, obviously.)
Is profile feedback available on those embedded targets?

--
Ian Collins
Nov 6 '08 #21
Ian Collins <ia******@hotmail.comwrites:
Phil Carmody wrote:
>Ian Collins <ia******@hotmail.comwrites:
>>Jack Klein wrote:
The programmer can often know things from the design of the code that
a compiler cannot discern without emulation or profiling of the entire
program.
Modern hosted compilers can use profile feedback to tune optimisations.
I haven't come across an embedded compilers that do this, but I expect
there are those that do.

Haven't you come across GCC as an embedded compiler? I know at Freescale
all ARM- and POWER- targetted C was compiled using GCC. (OK, the DSPs and
PICs had other compilers, obviously.)

Is profile feedback available on those embedded targets?
Well, I know there was GCC 4.1, and that at least supports -fprofile-arcs
and -fbranch-probabilities, etc., so yup, AFAICR it is.

Phil
--
We must respect the other fellow's religion, but only in the sense and to the
extent that we respect his theory that his wife is beautiful and his children
smart. -- Henry Louis Mencken (1880-1956), American editor and critic
Nov 6 '08 #22

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

Similar topics

12
by: Ioannis Vranos | last post by:
Just some thought on it, wanting to see any explanations. It was advised in this newsgroups that we should avoid the use of keyword register. However it is a language feature, and if it...
10
by: ajay | last post by:
some say floats can't be stored in register. size of int and float are same ( on some machine am i Wrong?) so if int can be delcared as register than why not float(where in and float are of same...
19
by: sabarish | last post by:
Hi friend, what is the use of function pointer in c language and where it is useful? tell with simple example...? plz help me.
17
by: Mike | last post by:
I'm trying to create a page: Three sections (left, topright and bottomright), each with a heading and scrolling (overflow) content. The size of these sections should be based upon the size of the...
33
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
1
by: Dinesh143 | last post by:
Where it is store the variables auto,static,extern,register,typedef,_declspec?
20
by: jacob navia | last post by:
Consider this code static typedef struct { int boo; } FOO; This provokes with MSVC: ------------------------------ Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64...
33
by: James H. Newman | last post by:
I have a portion of code along the following lines: volatile unsigned char x ; unsigned int f(unsigned char *y) ; When I do unsigned int z = f(&x) ;
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.