将主体中的定义类型传递给C中的标题 [英] Passing defined type in main to header in C

查看:121
本文介绍了将主体中的定义类型传递给C中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,正如标题所说,我应该在主文件中定义一个类型,并以某种方式将它传递给标题。我试图以任何方式做到这一点,但我没有想法。



我这样定义它:typedef int DATA;并在header中用作数据类型。



我试图在包含头文件之前插入typedef,但仍未识别。



任何想法?或者甚至不可能这样做?

  #include< stdio.h> 
#include< stdlib.h>

typedef int DATA;

#includePriorityQueue.h

int main(){
int priority;
DATA值;

这是我的主要开始

  #ifndef PRIORITY_QUEUE_H_ 
#define PRIORITY_QUEUE_H_

struct priorityQueue {
int priority;
DATA值;
struct priorityQueue * next;
};
typedef struct priorityQueue LINK;

void createEmpty(LINK ** head);
void add(LINK ** head,int p,DATA v);
void deleteElement(LINK ** head,int * p,DATA * v);
// void print(LINK * head);
void checkIfEmpty(LINK * head);
void destroy(LINK * head);
#endif

标题



<$编译:在PriorityQueue中发布(编译器:GNU GCC编译器)=== |
〜\PriorityQueue\PriorityQueue.h | 6 |错误:未知类型名称'DATA'|
〜\PriorityQueue\PriorityQueue.h | 11 |错误:未知类型名称'DATA'|
〜\PriorityQueue\PriorityQueue.h | 12 |错误:未知类型名称'DATA'|
〜\PriorityQueue\PriorityQueue.c | 10 |错误:未知类型名称'DATA'|
〜\PriorityQueue\PriorityQueue.c | 44 |错误:未知类型名称'DATA'|
|| ===构建失败:5个错误,0个警告(0分钟,0秒)=== |
用来代替我的目的地


解决方案

Put typedef int DATA; 在PriorityQueue.h中 struct priorityQueue 之前,并确保PriorityQueue.h包含在PriorityQueue.c中。


So, as the title says, I am supposed to define a type in main file and, somehow, pass it to header. I tried to do that in any way, but I am out of ideas.

I define it like this: "typedef int DATA;" and use it in header as a data type.

I tried inserting typedef before including header but still it isnt recognised.

Any ideas? Or it is not even possible to do it in this way?

#include <stdio.h>
#include <stdlib.h>

typedef int DATA;

#include "PriorityQueue.h"

int main(){
    int priority;
    DATA value;

That's beginning of my main

#ifndef PRIORITY_QUEUE_H_
#define PRIORITY_QUEUE_H_

struct priorityQueue{
    int priority;
    DATA value;
    struct priorityQueue *next;
};
typedef struct priorityQueue LINK;

void createEmpty(LINK **head);
void add(LINK **head, int p, DATA v);
void deleteElement(LINK **head, int *p, DATA *v);
//void print(LINK *head);
void checkIfEmpty(LINK *head);
void destroy(LINK *head);
#endif

Header

||=== Build: Release in PriorityQueue (compiler: GNU GCC Compiler) ===|
~\PriorityQueue\PriorityQueue.h|6|error: unknown type name 'DATA'|
~\PriorityQueue\PriorityQueue.h|11|error: unknown type name 'DATA'| 
~\PriorityQueue\PriorityQueue.h|12|error: unknown type name 'DATA'| 
~\PriorityQueue\PriorityQueue.c|10|error: unknown type name 'DATA'| 
~\PriorityQueue\PriorityQueue.c|44|error: unknown type name 'DATA'| 
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
 Used ~ instead of my destination

解决方案

Put typedef int DATA; in PriorityQueue.h before struct priorityQueue, and make sure PriorityQueue.h is included in PriorityQueue.c.

这篇关于将主体中的定义类型传递给C中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆