What's the differences between REGISTER and AUTO?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JOYCE

    What's the differences between REGISTER and AUTO?

    Look the subject,that's my problem!
    I hope someone can help me, thanks
  • James Kuyper

    #2
    Re: What's the differences between REGISTER and AUTO?

    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.

    Comment

    • Flash Gordon

      #3
      Re: What's the differences between REGISTER and AUTO?

      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 smap@spam.cause way.com
      If emailing me use my reply-to address
      See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/

      Comment

      • Nick Keighley

        #4
        Re: What's the differences between REGISTER and AUTO?

        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...@12 6.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






        Comment

        • Nick Keighley

          #5
          Re: What's the differences between REGISTER and AUTO?

          On 4 Nov, 12:51, Flash Gordon <s...@spam.caus eway.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

          Comment

          • Chris Dollin

            #6
            Re: What's the differences between REGISTER and AUTO?

            Nick Keighley wrote:
            On 4 Nov, 12:51, Flash Gordon <s...@spam.caus eway.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

            Comment

            • Stephen Sprunk

              #7
              Re: What's the differences between REGISTER and AUTO?

              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

              Comment

              • Keith Thompson

                #8
                Re: What's the differences between REGISTER and AUTO?

                Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                On 4 Nov, 12:51, Flash Gordon <s...@spam.caus eway.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_Keit h) kst-u@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"

                Comment

                • Nate Eldredge

                  #9
                  Re: What's the differences between REGISTER and AUTO?

                  Keith Thompson <kst-u@mib.orgwrites :
                  Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                  >On 4 Nov, 12:51, Flash Gordon <s...@spam.caus eway.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.

                  Comment

                  • Keith Thompson

                    #10
                    Re: What's the differences between REGISTER and AUTO?

                    Nate Eldredge <nate@vulcan.la nwrites:
                    Keith Thompson <kst-u@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_Keit h) kst-u@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"

                    Comment

                    • Ben Bacarisse

                      #11
                      Re: What's the differences between REGISTER and AUTO?

                      Nate Eldredge <nate@vulcan.la nwrites:
                      Keith Thompson <kst-u@mib.orgwrites :
                      >
                      >Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
                      >>On 4 Nov, 12:51, Flash Gordon <s...@spam.caus eway.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.

                      Comment

                      • Nate Eldredge

                        #12
                        Re: What's the differences between REGISTER and AUTO?

                        Keith Thompson <kst-u@mib.orgwrites :
                        Nate Eldredge <nate@vulcan.la nwrites:
                        >Keith Thompson <kst-u@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.

                        Comment

                        • Flash Gordon

                          #13
                          Re: What's the differences between REGISTER and AUTO?

                          Keith Thompson wrote, On 04/11/08 16:58:
                          Nate Eldredge <nate@vulcan.la nwrites:
                          >Keith Thompson <kst-u@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 smap@spam.cause way.com
                          If emailing me use my reply-to address
                          See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/

                          Comment

                          • Flash Gordon

                            #14
                            Re: What's the differences between REGISTER and AUTO?

                            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 smap@spam.cause way.com
                            If emailing me use my reply-to address
                            See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/

                            Comment

                            • Stephen Sprunk

                              #15
                              Re: What's the differences between REGISTER and AUTO?

                              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

                              Comment

                              Working...