Why can't I specify a storage class for formal function parameters?

When I do as below, the code works fine:

#include <stdio.h>
void test( int a)
{
 printf("a=%d\n",a);   
}

int main()
{
    test(10);
    return 1;
}

But when I do

#include <stdio.h>
void test( auto int a) // Or static int a Or extern int a
{
 printf("a=%d\n",a);   
}

int main()
{
    test(10);
    return 1;
}

It generates an error,

error: storage class specified for parameter 'a'

Why is this a mistake? What happens inside (memory management)?

But it works fine without errors when I do this:

void test( register int a)
{
 printf("a=%d\n",a);   
}

Why is this?

+6
source share
1 answer

To quote first C11, chapter 6.7.6.3

The only qualifier for the storage class that must be specified in the parameter declaration is register.

So this is explicitly stated in the standard.

, , , static/extern, , , .

  • ; , ? , static , auto .

  • , extern .


, C11, main() int main(void), .

+7

All Articles