将指针传递给字符串作为函数的参数时发生类型冲突

dan*_*yxn 1 c struct pointers

错误说明正如我在主题中所写的那样,当我尝试将指针传递给使用结构体数组构造的结构体时,我遇到了冲突类型错误。您是否有删除此错误的建议?我缺少什么?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define N 10

void count_length(struct abc *_el);

struct vector {
    double x;
    double y;
};

struct abc {
    struct vector vec;
    double length;
};

int main(void)
{
    struct abc set[N];
    srand(time(NULL));
    for(int i=0; i<N; i++)
    {
        set[i].vec.x = rand();
        set[i].vec.y = rand(); 
        count_length(&set[i]);
    }


}

void count_length(struct abc *_el)
{
    for(int i=0; i<N; i++)
        _el->length = sqrt(pow(_el->vec.x, 2.0) + pow(_el->vec.y, 2.0));
}
Run Code Online (Sandbox Code Playgroud)

Ach*_*hal 6

保留函数声明

void count_length(struct abc *_el); /* compiler don't knows what is struct abc as you have defined it after this statement */
Run Code Online (Sandbox Code Playgroud)

之后的结构不是之前的。例如

struct vector {
    double x;
    double y;
};

struct abc {
    struct vector vec;
    double length;
};
void count_length(struct abc *_el); /* here compiler knows what is struct abc */
Run Code Online (Sandbox Code Playgroud)