difference between these TWO Declerations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shrichandra
    New Member
    • Jul 2007
    • 4

    difference between these TWO Declerations

    Hi...
    I want to know difference between these two declaration in C language..

    register int i;
    int _i;
  • shrichandra
    New Member
    • Jul 2007
    • 4

    #2
    difference between these TWO Declerations

    Hi...
    I want to know difference between these two declaration in C language..

    register int i;
    int _i;

    Comment

    • Meetee
      Recognized Expert Contributor
      • Dec 2006
      • 928

      #3
      Originally posted by shrichandra
      Hi...
      I want to know difference between these two declaration in C language..

      register int i;
      int _i;
      "register" is keyword used to give a hint to the compiler as to how to generate code. In this case, you are asking the compiler to try to keep a variable in a register instead of in memory. Registers can be accessed much faster than memory locations.

      Regards

      Comment

      • dumparun
        New Member
        • Feb 2007
        • 26

        #4
        Originally posted by zodilla58
        "register" is keyword used to give a hint to the compiler as to how to generate code. In this case, you are asking the compiler to try to keep a variable in a register instead of in memory. Registers can be accessed much faster than memory locations.

        Regards
        Register is only a request to the compiler....
        adding register keyword doesnt guarantee, that the variable goes into the register.

        Basically used in embedded programing for faster access of the variables

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          _i and i are both int variables.

          The register suggests to the compiler that ti would be better to keep the variable in a processor register rather than in memory. The compiler is free to ignore the suggestion.

          You never use the register keyword unless you really know what you are doing

          Comment

          • Silent1Mezzo
            New Member
            • Feb 2007
            • 208

            #6
            Also please do not double post.

            Comment

            Working...