编译错误
#include <stdio.h>
#include <stdlib.h>
#include "he.h"
static int COUNT = 10;
int main() {
printf("-----\n");
while (COUNT > 0) {
func1(); // **此处方法调用会报 Implicit declaration of function 'func1' is invalid in C99**
// ^
COUNT --;
}
return 0;
}
void func1() {
static int THINGY = 5;
THINGY ++;
printf(" thingy is %d, count is %d\n", THINGY, COUNT);
}
解决方案
#include <stdio.h>
#include <stdlib.h>
#include "he.h"
static int COUNT = 10;
void func1() { // **将方法定义在 main() 函数上边即可**
static int THINGY = 5;
THINGY ++;
printf(" thingy is %d, count is %d\n", THINGY, COUNT);
}
int main() {
printf("-----\n");
while (COUNT > 0) {
func1();
COUNT --;
}
return 0;
}
or