Thread: difference between register int and normal int

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110

    difference between register int and normal int

    First of all: i didnt wanted to put this on the C board because its not a real problem i just want to know what the difference is between a register int and a normal int.
    According to my lib reference from BC 4.5
    register int :to optimize access and reduce code.
    Items declared with the register have a global lifetime.
    So why dont we use register int where we can ( known that its possibly faster in processing) instead of using a normal int ?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    I don't know anything about them but maybe it's because they are platform specific? (which they may not be, I'm just conjecturing)

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I think you'll find the keyword is retained for backward compatibility reasons. Most modern compilers ignore it, they optimise register usage themselves.

    >>> platform specific

    The register storage class is part of the ANSI standard.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >So why dont we use register int where we can ( known that its possibly faster in processing) instead of using a normal int ?
    Because the compiler can and probably will ignore your hint in the assumption that it is in a better position to know where to optimize. You also cannot take the address of a register variable even if it isn't actually placed in a register, this is typically considered a bad thing.

    -Prelude
    My best code is written with the delete key.

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    So my conclusion is dont use a register int because most recent compilers wont notice the difference. With that i mean that they will see if it necesseray to have a register int and if not they'll translate my register int into a normal int.

    If im wrong correct me.
    Btw thx because i once saw some code with a register in it and wondered what the purpose was 4 it.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Your right. The class specifier is at best, a suggestion. Consider, there is no restriction on the number of register variables you can declare in a routine, but there is a limited number of registers!

    Let the compiler do it, by the time it has re-arranged your code, it is in the best position to decide where to put things.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Thx got it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Display Lists (OpenGL)
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 06-05-2005, 12:11 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM