问题
#include <stdio.h>
int w=7,v=0;
shortf(short a, short *b)
{
a++;(*b)++;w++;v++;
printf("13: %d %d %d",a,v,w); return a;
}
int main()
{
return 0;
}
This is part of my code. It was given to me by a teacher in my University, but when I write it I get 10+ warnings and errors, this is one of them. I get a " return type defaults to 'int' " warning for Line 4. Why? Note: I am only allowed to use C.
回答1:
You did not declare a return type for the function shortf
. And so the compiler warned you that the default type of int
will be used.
You should always declare a return value type. My guess is that the code has just been transcribed incorrectly. I think it should be:
short f(short a, short *b)
回答2:
You forget to declare the return type of your function shortf
. In C89, if return type of a function is omitted, the function is presumed to return a value of int
type (by default). It should be
short shortf(short a, short *b) {...}
In C99 and latter, it is illegal to omit the return type of a function.
来源:https://stackoverflow.com/questions/21079849/getting-a-return-type-defaults-to-int-warning-when-i-declare-shortf-functi