This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

"register"

hello,

If i enter the word 'register' it appears in blue, so that means it is a 'reserved keyword'.I wonder what the purpose is of this keyword 'register' and for what i can use it... Can anybody help me?

(I'm a newbie in Keil C51 compiler.)

thanks and greetz

Parents
  • ISO/IEC 9899:1990 (the international standard definition of the 'C' programming language), states:

    "A declaration of an identifier for an object with storage-class specifier register suggests that acces to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined"

    In other words, as Graham says, it is a hint to the Compiler - but the compiler is under no obligation to take any specific notice of the hint!

    ISO/IEC 9899:1990 defines the term "implementation-defined" to mean,

    "Behaviour ... that depends upon the characteristics of the implementation and that each implementation shall document" (my emphasis)

    I'm not sure exactly where in the Keil Manuals the behaviour of the register keyword is specifically documented...?

Reply
  • ISO/IEC 9899:1990 (the international standard definition of the 'C' programming language), states:

    "A declaration of an identifier for an object with storage-class specifier register suggests that acces to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined"

    In other words, as Graham says, it is a hint to the Compiler - but the compiler is under no obligation to take any specific notice of the hint!

    ISO/IEC 9899:1990 defines the term "implementation-defined" to mean,

    "Behaviour ... that depends upon the characteristics of the implementation and that each implementation shall document" (my emphasis)

    I'm not sure exactly where in the Keil Manuals the behaviour of the register keyword is specifically documented...?

Children
  • "I'm not sure exactly where in the Keil Manuals the behaviour of the register keyword is specifically documented...?"

    As a standard 'C' keyword I doubt that it is documented by Keil any more than any other standard keyword. The manuals don't attempt to be a standard 'C' primer - fundamental 'C' knowledge is assumed.

    Stefan

  • "The manuals don't attempt to be a standard 'C' primer - fundamental 'C' knowledge is assumed."

    True, but this particular keyword is identified by the standard as implementation-defined, and the standard specifically defines that to mean,

    "Behaviour ... that depends upon the characteristics of the implementation and that each implementation shall document" (my emphasis)

  • "True, but this particular keyword is identified by the standard as implementation-defined, and the standard specifically defines that to mean,

    "Behaviour ... that depends upon the characteristics of the implementation and that each implementation shall document" (my emphasis)"

    We can therefore safely assume that as no implementation defined behaviour has been documented the register keyword does nothing.

    Stefan

  • If you want to find out, create a small function, inspect the assembly generated, find a variable that is memory bound. Then decalre it register and compare the assembly.
    Elementary my dear Watson

    Erik

  • "If you want to find out, create a small function, inspect the assembly generated, find a variable that is memory bound. Then decalre it register and compare the assembly.
    Elementary my dear Watson"

    Not quite. Even if the compiler does observe the register keyword there is no guarantee that it will do so in the particular test that you perform.

    Stefan

  • "Not quite. Even if the compiler does observe the register keyword there is no guarantee that it will do so in the particular test that you perform."

    Now, what is it that Erik keeps saying about testing...? ;-)

  • Now, what is it that Erik keeps saying about testing...? ;-)
    Testing, Yes absolutely. Trying is OK.

    Trying the above would never have any effect on whether the end product would work or not.
    If the reason for using "register" is a time critical function, C should not have been used anyhow.

    Erik

  • "If the reason for using "register" is a time critical function, C should not have been used anyhow."

    What other possible reason could there be? Quoting from the previously quoted section of the standard:

    "A declaration of an identifier for an object with storage-class specifier register suggests that acces to the object be as fast as possible."

    Stefan

  • "If the reason for using "register" is a time critical function, C should not have been used anyhow."

    What other possible reason could there be?


    Here we are in PC land again. for a PC application you might want something as fast as possible without the programmer making any effort - typical PC programmer attitude.
    For a microprocessor application the above doesn't cut it, in that case it is as fast as possible with the programmer making an effort - which should be the attitude of every microcontroller programmer - and that is impossible in C.

    Please note: I recommend that all non time critical code be written in C, I am not an assembler fanatic; however when I see microcontroller programmers try to avoid the dreadful assembler I cringe.

    Erik

  • hi,

    seems to be a popular topic that 'register' thing,however, thanks for the info

    greetzzz,
    peter

  • And the result is:

    The register keyword is NOT ignored.