Forcing the compiler to use a certain register for a certain variable

c, clang, gcc, linux, x86-64

Solution

gcc can do it.

The already cited gcc docs answers your question of how to force a variable into a certain register.

To stop the compiler from generating code using this register for other purposes, use the gcc switch `-ffixed-reg` (see gcc doc for details).

Problem

Is it possible to force a compiler (`gcc` or `clang` in my case) to use a certain register, lets say `R15` on `x86_64` for a certain variable and also prohibit it from using `R15` for any other purpose besides that variable.

Original source