Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function declarators in C

Tags:

c

§6.7.6.3 Function declarators

2) The only storage-class specifier that shall occur in a parameter declaration is register.

§6.7.6.3 Function declarators

13) The storage-class specifier in the declaration specifiers for a parameter declaration, if present, is ignored unless the declared parameter is one of the members of the parameter type list for a function definition.

I have declared and defined like this...

int function(static int param)
{
    return param;
}

Visual Studio is throwing a warning. What I understood is, if we use register as a parameter type in the declaration of a function, it should compile without warning. Other than register, it will ignore the storage class and throw a warning message to user. Is my understanding proper?

Thanks

like image 685
StackIT Avatar asked Jun 14 '26 11:06

StackIT


2 Answers

I believe 6.7.6.3 is saying that storage-class specifiers are ignored in function declarations; it says that it's ignored unless the parameter is part of the parameter type list for a function definition. Since you're showing a function definition, it would not be proper for the compiler to ignore this invalid storage-class specifier here.

like image 176
Ernest Friedman-Hill Avatar answered Jun 17 '26 03:06

Ernest Friedman-Hill


First of all the compiler that you get with Visual Studio is not according to c99/c11 standard.

The function definition should not allow the use of storage class specifiers other than register. It should flag it as a bad use of storage class. As stated, VS compiler is not according to standard, it is throwing a warning message.