1

This would seem like a common use case. Maybe we want to declare a variable in a function and we want to make it static so that the variable will retain its value at multiple function calls.

We also want to tell the compiler to try to store the variable in a CPU register for faster access.

However this is not possible in C.

int foo()
{
   static register int a;
   a++:

}

This code gives the following error.

 multiple storage classes in declaration specifiers

Why is it not possible to have multiple storage class specifier when declaring a variable?

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • 9
    Because hogging a register for the lifetime of the static variable is an unreasonable requirement? – Weather Vane Oct 04 '17 at 12:21
  • Also see ["register" keyword in C?](https://stackoverflow.com/questions/578202/register-keyword-in-c) for why the usage doesn't buy you anything anyway. – Bo Persson Oct 04 '17 at 14:05

0 Answers0