C不兼容的指针类型消息似乎列出了预期和实际的相同指针类型

Hos*_*sty 3 c arrays struct pointers compiler-errors

我正在尝试编写代码以动态地为结构数组分配内存。我想将与堆内存空间关联的指针传递给另一个函数,以供进一步使用。下面的代码示例是我想做的一个粗略示例(为简洁起见,此处省略):

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/sha.h>
#include <time.h>

struct password_struct;
void create_password(char password_seeds[], struct password_struct* user_passwords);

void main() {


    char password_seeds[100];
    int num_passwords = 5;
    struct password_struct {
        char password[17];
        char hash[65];
        int entropy;
    };


    struct password_struct *user_passwords = malloc(num_passwords * sizeof(struct password_struct));

    create_password(password_seeds, user_passwords);
    free(user_passwords);
}


void create_password(char password_seeds[], struct password_struct* user_passwords){

}
Run Code Online (Sandbox Code Playgroud)

当我尝试对此进行编译时,出现以下错误:

In function ‘main’:
     c:24:5: warning: passing argument 2 of ‘create_password’ from incompatible pointer type [enabled by default]
     create_password(password_seeds, user_passwords);
     ^
     c:8:6: note: expected ‘struct password_struct *’ but argument is of type ‘struct password_struct *’
     void create_password(char password_seeds[], struct password_struct* user_passwords);
          ^
Run Code Online (Sandbox Code Playgroud)

似乎列出了与实际和预期指针类型相同的指针类型。任何帮助将不胜感激。

Sou*_*osh 5

这是因为,结构的定义password_struct位于内部main(),而在范围外部不可见。

将结构定义移到文件范围内(外部main()或任何其他函数)。

也就是说,请参见以下内容:C的main()函数的有效签名是什么?