我有一个.c和.h文件:
misc.c
#include "misc.h"
int isAllZeros(int *arr, int l)
{
int i;
int allZeros = 1;
for (i = 0; i<l; i++)
{
if(arr[i])
{
allZeros = 0;
break;
}
}
return allZeros;
}
int containsDup(int *arr1, int *arr2, int l1,int l2)
{
int i,k;
int dup = 0;
for (i = 0; i<l1; i++)
{
for (k=0;k<l2;k++)
{
if(arr1[i] == arr2[k])
{
dup = 1;
break;
}
}
if (dup) break;
}
return dup;
}
和misc.h
#ifndef misc_h
#define misc_h
#include "ext.h"
#include "ext_obex.h"
#include "ext_path.h"
typedef struct _MNote {
t_uint32 t;
t_uint8 note, vel;
} t_MNote;
typedef struct _MPed {
t_uint32 t;
t_uint8 state;
} t_MPed;
typedef struct _Note {
t_uint32 t, length;
t_uint8 note, vel;
} t_Note;
typedef struct _chordInd {
int length;
int notes[5];
} t_chordInd;
int isAllZeros(int *arr, int l);
int containsDup(int *arr1, int *arr2, int l1,int l2);
#endif
在主.c文件中,第一行是#include "misc.h"
。它看到在.h文件中声明的结构,但是没有在.c文件中看到函数定义。当我将#include "misc.c"
添加到主文件时它可以工作,但为什么它不能简单地用.h?