Pregunta

#include <stdio.h>

void foo(auto int i); // line 3

int main()
{
    foo(10);
}

void foo(auto int i) // line 13
{
    printf("%d\n", i );
}

What is wrong in this code? This program is not compiling.

Errors I am seeing are as follows:

main.c:3:27: error: storage class specified for parameter 'i'
     void foo(auto int i);

main.c:13:27: error: storage class specified for parameter 'i'
     void foo(auto int i)
¿Fue útil?

Solución 2

The only storage class specifier that is valid in a parameter declaration is register, we can see this from the draft C99 standard section 6.7.5.3 Function declarators (including prototypes) paragraph 2 which says:

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

this is section 6.7.6.3 in C11.

the storage class specifiers from section 6.7.1 Storage-class specifiers are as follows:

typedef
extern
static
auto
register

Otros consejos

auto is a storage class specifier. This is used for local variables(automatic local variables) You can't put it in the declaration of function parameter.

On compiling you should get the error:

[Error] storage class specified for parameter 'i'  

In C, You are not allowed to put a storage class specifier in the parameter declaration (except register)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top