Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 函数错误的冲突类型_C_Pointers_Struct - Fatal编程技术网

C 函数错误的冲突类型

C 函数错误的冲突类型,c,pointers,struct,C,Pointers,Struct,这是我第一次使用structs,我不确定我遗漏了什么。下面的代码在第38行给出了以下错误: “加密”的冲突类型 代码如下: #include<stdio.h> #include<stdint.h> void encrypt(struct bitfield24* , struct bitfield24*, struct bitfield24*); struct bitfield24 { uint32_t value : 24; }; void main(){

这是我第一次使用structs,我不确定我遗漏了什么。下面的代码在第38行给出了以下错误: “加密”的冲突类型 代码如下:

#include<stdio.h>
#include<stdint.h>

void encrypt(struct bitfield24* , struct bitfield24*, struct bitfield24*);

struct bitfield24 {
  uint32_t value : 24;
};

void main(){
    struct bitfield24 key[4];
    key[0].value = 0;
    key[1].value = 1;
    key[2].value = 2;
    key[3].value = 3;


    struct bitfield24 plain_text[2];
    plain_text[0].value = 0;
    plain_text[0].value = 1;

    struct bitfield24 cipher_text[2];
    cipher_text[0].value = 0;
    cipher_text[1].value = 0;

    struct bitfield24*  pt = plain_text;
    struct bitfield24*  ct = cipher_text;   
    struct bitfield24*  k = key;   

    encrypt(pt, ct, k);    // line 30
    printf("%x ,", ct[1].value);
    printf("%x \n", ct[0].value);
}

 /*
 * Ecnryption Method
 */
void encrypt(struct bitfield24* pt, struct bitfield24* ct, struct bitfield24* k){ //line 38

        // Encryption Algorithm
    }
#包括
#包括
void encrypt(struct bitfield24*、struct bitfield24*、struct bitfield24*);
结构位字段24{
uint32_t值:24;
};
void main(){
结构bitfield24键[4];
键[0]。值=0;
键[1]。值=1;
键[2]。值=2;
键[3]。值=3;
结构位字段24纯文本[2];
纯文本[0]。值=0;
纯文本[0]。值=1;
结构bitfield24密码文本[2];
密码文本[0]。值=0;
密码文本[1]。值=0;
结构bitfield24*pt=纯文本;
结构bitfield24*ct=密码文本;
结构bitfield24*k=键;
加密(pt,ct,k);//第30行
printf(“%x”,ct[1]。值);
printf(“%x\n”,ct[0]。值);
}
/*
*加密法
*/
void encrypt(struct bitfield24*pt、struct bitfield24*ct、struct bitfield24*k){//第38行
//加密算法
}
除此之外,以下是与代码相关的警告。第30行的所有3个参数都会引发相同的警告。
注意:应为“struct bitfield24*”,但参数类型为“struct bitfield24*”请帮助我解决此问题


如果需要,我可以提供更多信息。

您的代码存在两个主要问题。首先,在定义结构本身之前,不能使用结构声明方法原型。解决方案是首先定义结构:

#include<stdio.h>
#include<stdint.h>

struct bitfield24 {
    uint32_t value : 24;
};

void encrypt(struct bitfield24* , struct bitfield24*, struct bitfield24*);

在此之后,您的代码就可以编译了。

Move
enccript()
prototype After struct definition。谢谢您的回答,这很有效。我的代码也符合
void main()
的要求并运行良好。我的main中没有任何return语句。@NanoNi您的代码可以使用声明为
void
main
编译,但它不符合标准,也不会在每个系统上运行。例如,它无法在我的Mac上使用
clang
构建。很自然,在更正主函数声明后,代码还需要在最后一个右大括号之前有一个“return 0”。
int main(){