Search code examples
cgcc

cases for gcc to ignore register declaration?


K&R says

compilers are free to ignore the advice (register declaration).

In what cases, gcc would ignore if I define register int x = 4;?


Solution

  • This is totally implementation-dependent.

    In general, you should trust the compiler to put variables to register and not define them yourself.

    C99 6.7.1 Storage-class specifiers

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

    Plus, C++11 has deprecated the use of the register keyword as a storage-class-specifier, maybe sometime in the future C will do the same.