【问题标题】:have a conflicting types error [closed]有冲突的类型错误[关闭]
【发布时间】:2013-04-25 23:48:27
【问题描述】:

编译我的 c 文件时出现此错误 我似乎无法让我的类型对这个程序正确,我将如何解决这个问题 我把我的 .h 文件和我的 .c 文件放在一起

错误

example4.c:35: error: conflicting types for ‘h’
example4.h:8: error: previous declaration of ‘h’ was here

example4.h 代码

typedef struct{
        int x;
        char s[10];
}Record;

void f(Record *r);
void g(Record r);
void h(const Record r);

example4.c 代码

#include <stdio.h>
#include <string.h>
#include "example4.h"

int main()
{
        Record value , *ptr;

        ptr = &value;

        value.x = 1;
        strcpy(value.s, "XYZ");

        f(ptr);
        printf("\nValue of x %d", ptr -> x);
        printf("\nValue of s %s", ptr->s);


        return 0;
}

void f(Record *r)
{
        r->x *= 10;
        (*r).s[0] = 'A';
}

void g(Record r)
{
        r.x *= 100;
        r.s[0] = 'B';
}

void h(Record *r)
{
        r->x *= 1000;
        r->s[0] = 'C';
}

【问题讨论】:

  • 请参阅Error: assignment of read-only location 了解此问题的前传。
  • “我将如何解决这个问题”——显然,通过使类型相同。您在发布代码之前是否查看过代码?

标签: c compiler-errors


【解决方案1】:

你的头文件声明void h(const Record r);

当您的源文件声明 void h(Record *r)

当您尝试将answer I gave you 应用于this question 时,您修复了源文件,但忘记修复标题。

【讨论】:

    猜你喜欢
    • 2018-04-30
    • 2015-07-27
    • 2016-02-07
    • 2013-03-25
    • 1970-01-01
    • 2014-03-10
    • 2012-10-04
    • 2013-04-24
    • 1970-01-01
    相关资源
    最近更新 更多