StackIT
StackIT

Reputation: 1190

Function declarators in 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

Upvotes: 3

Views: 1351

Answers (3)

Gangadhar
Gangadhar

Reputation: 10516

AS said Visual Studio is not according to c99/c11 standard.
that is why this is throwing as warning. if you compile with gcc ..

you will get error: storage class specified for parameter âparamâ at the place of declaration of function and defination of the function

You can use only register should not other ones Like static, extern

Upvotes: 1

user1814023
user1814023

Reputation:

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.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

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.

Upvotes: 7

Related Questions