.h头文件的使用方法

这篇博客详细介绍了.h头文件在C语言中的应用,包括宏定义、结构体、联合体、枚举声明,以及typedef和外部函数、全局变量的声明。强调了全局变量在.h文件中的声明需配合extern关键字,并指出有初始值的变量应在相应的.c文件中赋值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 宏定义(预处理#define);

2. 结构、联合和枚举声明;

3. typedef声明;

4. 外部函数声明;

5. 全局变量声明。

可以定义在global.h文件中,但记得写extern,然后再在global.c中写一遍,不加extern,如果有赋初值的变量,在global.h中不赋值,在global.c中赋值。

global.h

#ifndef __GLOBAL_H_
#define __GLOBAL_H_

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <memory.h>
#include <vector>
#include <windows.h>

using namespace std;

#include "random.h"

#define GNEx_nodes 128
#define GNEx_edge 1024
#define GNEx_QR 1.0/(2*GNEx_edge)

#define INF 1.0e+30
#define archive_size 500   /* set capacity of archive */

extern int     numVariables;
extern int     numObjectives;
extern int     popsize;
extern int     niche;
extern int     mt;
extern int     max_gen;
extern int     Tr;
extern int     nr;

//*
extern char    strFunctionType[256];
extern ch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值