包含c语言结构体的头文件,使用C struct而不包含头文件

我的基本问题是我想通过在我的代码中不包含该头文件来使用头文件中定义的一些结构和函数.

头文件由工具生成.由于我无法访问头文件,因此无法将其包含在我的程序中.

这是我的场景的一个简单示例:

first.h

#ifndef FIRST_H_GUARD

#define FIRST_H_GUARD

typedef struct ComplexS {

float real;

float imag;

} Complex;

Complex add(Complex a, Complex b);

// Other structs and functions

#endif

first.c

#include "first.h"

Complex add(Complex a, Complex b) {

Complex res;

res.real = a.real + b.real;

res.imag = a.imag + b.imag;

return res;

}

my_program.c

// I cannot/do not want to include the first.h header file here

// but I want to use the structs and functions from the first.h

#include

int main() {

Complex a; a.real = 3; a.imag = 4;

Complex b; b.real = 6; b.imag = 2;

Complex c = add(a, b);

printf("Result (%4.2f, %4.2f)\n", c.real, c.imag);

return 0;

}

我的目的是为my_program构建一个目标文件,然后使用链接器将目标文件链接到一个可执行文件中.我想在C中实现什么?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值