Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why only "register" storage-class specifier can be used inside parameter declaration?

Tags:

c

Why does the snippet of code below produce an error?

int fun(auto int arg)
{
    return 1;
}

If I use "register" in place of "auto", it works fine. Is there any reason behind this or is it just the way C standard is defined?

like image 745
Radha Gogia Avatar asked Dec 09 '25 11:12

Radha Gogia


1 Answers

Allowing register is likely an historical artifact from the times when compilers were not sophisticated enough to optimize register allocations as well or better than humans. Back then it was desirable to tell the compiler that a particular parameter should be passed in one of CPU's registers, not through a stack frame.

No other storage class specifier could possibly make sense here: you cannot pass parameters as extern or static, while auto would create confusion.

like image 182
Sergey Kalinichenko Avatar answered Dec 10 '25 23:12

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!