| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 830 人关注过本帖
标题:请教头文件问题……
只看楼主 加入收藏
vs_inzaghi
Rank: 5Rank: 5
来 自:湖北
等 级:职业侠客
威 望:1
帖 子:303
专家分:364
注 册:2009-8-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
请教头文件问题……
不知道我的头文件找错没……应该是软件的安装路径里面的include文件夹里面吧……
比如math.h头文件,我想问的是,这里面除了预编译和定义之类的就没其他内容了,也就是说,如果我引用其中的sqrt函数,为什么能帮我把平方根计算出来,好像这里面没有数据之间的计算操作啊……难道是在编译过程中完成的?
那么,如果我自己想定义一个函数比如max函数用来比较2个数的大小,当然函数很好写,然后我在自己添加一个头文件,把这个函数放在里面,以后直接包含这个头文件就可以使用max函数了,这样可以吗?
可是,我感觉我怎样也不可能写出像下面的头文件一样的代码……
所以,请教高手指点一二,小菜不甚感激……
比如,当我打开一个math.h的头文件后……
代码如下:
/*    math.h

    Definitions for the math floating point package.

    Copyright (c) Borland International 1987,1988
    All Rights Reserved.
*/
#if __STDC__
#define _Cdecl
#else
#define _Cdecl    cdecl
#endif

#ifndef  _MATH_H
#define  _MATH_H 1

#define EDOM    33        /* Math argument */
#define ERANGE    34        /* Result too large */

#define HUGE_VAL    _huge_dble
extern double _Cdecl _huge_dble;

int    _Cdecl abs   (int x);
double    _Cdecl acos  (double x);
double    _Cdecl asin  (double x);
double    _Cdecl atan  (double x);
double    _Cdecl atan2 (double y, double x);
double    _Cdecl atof  (const char *s);
double    _Cdecl ceil  (double x);
double    _Cdecl cos   (double x);
double    _Cdecl cosh  (double x);
double    _Cdecl exp   (double x);
double    _Cdecl fabs  (double x);
double    _Cdecl floor (double x);
double    _Cdecl fmod  (double x, double y);
double    _Cdecl frexp (double x, int *exponent);
long    _Cdecl labs  (long x);
double    _Cdecl ldexp (double x, int exponent);
double    _Cdecl log   (double x);
double    _Cdecl log10 (double x);
double    _Cdecl modf  (double x, double *ipart);
double    _Cdecl pow   (double x, double y);
double    _Cdecl sin   (double x);
double    _Cdecl sinh  (double x);
double    _Cdecl sqrt  (double x);
double    _Cdecl tan   (double x);
double    _Cdecl tanh  (double x);

struct    exception
{
    int    type;
    char   *name;
    double    arg1, arg2, retval;
};

int _Cdecl matherr (struct exception *e);

#if !__STDC__
double    cdecl hypot (double x, double y);
double    cdecl poly  (double x, int degree, double coeffs []);
double    cdecl pow10 (int p);

struct complex        /* as used by "cabs" function */
{
    double  x, y;
};

#define cabs(z)     (hypot ((z).x, (z).y))

/*  The customary matherr() exception handler for maths functions is
    not compatible with the x3j11 draft standard for C.  _matherr() is
    provided as a compromise.
*/

typedef enum
{
    DOMAIN = 1,    /* argument domain error -- log (-1)        */
    SING,       /* argument singularity  -- pow (0,-2))     */
    OVERFLOW,       /* overflow range error  -- exp (1000)      */
    UNDERFLOW,       /* underflow range error -- exp (-1000)     */
    TLOSS,       /* total loss of significance -- sin(10e70) */
    PLOSS,       /* partial loss of signif. -- not used      */
}   _mexcep;

double _Cdecl _matherr (_mexcep why, char *fun, double  *arg1p,
            double  *arg2p, double  retval);

/* Constants rounded for 21 decimals. */
#define M_E        2.71828182845904523536
#define M_LOG2E        1.44269504088896340736
#define M_LOG10E    0.434294481903251827651
#define M_LN2        0.693147180559945309417
#define M_LN10        2.30258509299404568402
#define M_PI        3.14159265358979323846
#define M_PI_2        1.57079632679489661923
#define M_PI_4        0.785398163397448309116
#define M_1_PI        0.318309886183790671538
#define M_2_PI        0.636619772367581343076
#define M_1_SQRTPI    0.564189583547756286948
#define M_2_SQRTPI    1.12837916709551257390
#define M_SQRT2        1.41421356237309504880
#define M_SQRT_2    0.707106781186547524401

#endif    /* __STDC__ */

#endif
 
搜索更多相关主题的帖子: 文件 教头 
2010-07-25 11:19
ouyangouyang
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:273
专家分:579
注 册:2009-10-8
收藏
得分:2 
我也想知道解释,高手过来看看啊

多少恨, 昨夜梦魂中。 还似旧时游上苑, 车如流水马如龙; 花月正春风!
2010-07-25 23:31
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:16 
是没有代码。那些代码都编译好了打包在一个叫库的文件里了。
库里面都是一些编译好了的目标文件,你写的程序如果调用了库里的文件,那么会在链接的时候(这个过程应该知道吧,已经在编译之后了),链过来直接用。

库有大量的代码,不可能是再编译的,要是那样,你随便编译一个程序就得几个小时。

如果你感兴趣 math 的话,其实 intel 的 CPU 在硬件级上就提供了你说的比如开方的运算。


如果你写了程序,也想包个头文件就用,那么你也得把它们做成库才行。库有两种,一个是静态的,一个是动态的。
头文件里一般包括 宏,函数,结构之类的声明。虽然你看着可能感觉写的挺复杂,但其实就是那个模式,写好的头文件一般看上去都是那个样子的。你多看几个马上就看出规律了。

比较复杂的是编写可移植的东西,那是另外一门学问,和你现在问的关系不大。
2010-07-26 01:25
teethandnail
Rank: 1
等 级:新手上路
帖 子:1
专家分:2
注 册:2010-7-26
收藏
得分:2 
我也想知道,并且里面的程序跟我们平常用C编写的格式也不一样
2010-07-26 01:26
vs_inzaghi
Rank: 5Rank: 5
来 自:湖北
等 级:职业侠客
威 望:1
帖 子:303
专家分:364
注 册:2009-8-17
收藏
得分:0 
回复 3楼 pangding
多谢指点,学习了……

我很懒,但我讨厌别人说我懒……
2010-07-26 13:00
快速回复:请教头文件问题……
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017921 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved