刚发现的几个关于头文件的问题,不知道大家是否清楚,但相信你绝对会有兴趣

vamking_boy 2009-03-07 05:36:02
直接点,比如#include <stdio.h> .. #inlcude <conio.h> ...#include <bios.h>
等等。
我们可以直接调用里面的函数,比如 scanf() 和 printf() 函数,以及 strcmp()函数等等,可是到哪里可以找到这些函数的源代码?
还有头文件里有很多的东西,比如:
typedef struct {
short level; /* fill/empty level of buffer */
unsigned flags; /* File status flags */
char fd; /* File descriptor */
unsigned char hold; /* Ungetc char if no buffer */
short bsize; /* Buffer size */
unsigned char *buffer; /* Data transfer buffer */
unsigned char *curp; /* Current active pointer */
unsigned istemp; /* Temporary file indicator */
short token; /* Used for validity checking */
} FILE;
的定义,为什么要这样定义?还有:
int _Cdecl fclose (FILE *stream);
int _Cdecl fflush (FILE *stream);
int _Cdecl fgetc (FILE *stream);
int _Cdecl fgetpos (FILE *stream, fpos_t *pos);
char *_Cdecl fgets (char *s, int n, FILE *stream);
FILE *_Cdecl fopen (const char *path, const char *mode);
.......
等等类似的东西,比如这个_Cdecl 就不理解,
谁能解释下 _Cdecl 这个东西,因为它是在 int 后的,怎么都看不懂........................
以及谁能提供点这方面的资料让小弟去研究下,谢谢了!!
...全文
131 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
dobymyself 2009-03-07
  • 打赏
  • 举报
回复
你F11单步调试 可以进去
mymtom 2009-03-07
  • 打赏
  • 举报
回复
去看C程序的源码。
http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libc/i386/
  • 打赏
  • 举报
回复
/***
*strcat.c - contains strcat() and strcpy()
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Strcpy() copies one string onto another.
*
* Strcat() concatenates (appends) a copy of the source string to the
* end of the destination string, returning the destination string.
*
*******************************************************************************/

#include <cruntime.h>
#include <string.h>

#ifndef _MBSCAT
#ifdef _MSC_VER
#pragma function(strcat,strcpy)
#endif /* _MSC_VER */
#endif /* _MBSCAT */

/***
*char *strcat(dst, src) - concatenate (append) one string to another
*
*Purpose:
* Concatenates src onto the end of dest. Assumes enough
* space in dest.
*
*Entry:
* char *dst - string to which "src" is to be appended
* const char *src - string to be appended to the end of "dst"
*
*Exit:
* The address of "dst"
*
*Exceptions:
*
*******************************************************************************/

char * __cdecl strcat (
char * dst,
const char * src
)
{
char * cp = dst;

while( *cp )
cp++; /* find end of dst */

while( *cp++ = *src++ ) ; /* Copy src to end of dst */

return( dst ); /* return dst */

}


/***
*char *strcpy(dst, src) - copy one string over another
*
*Purpose:
* Copies the string src into the spot specified by
* dest; assumes enough room.
*
*Entry:
* char * dst - string over which "src" is to be copied
* const char * src - string to be copied over "dst"
*
*Exit:
* The address of "dst"
*
*Exceptions:
*******************************************************************************/

char * __cdecl strcpy(char * dst, const char * src)
{
char * cp = dst;

while( *cp++ = *src++ )
; /* Copy src over dst */

return( dst );
}
  • 打赏
  • 举报
回复
随便贴几个,你怎么找的?

/***
*strcmp.c - routine to compare two strings (for equal, less, or greater)
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Compares two string, determining their lexical order.
*
*******************************************************************************/

#include <cruntime.h>
#include <string.h>

#ifdef _MSC_VER
#pragma function(strcmp)
#endif /* _MSC_VER */

/***
*strcmp - compare two strings, returning less than, equal to, or greater than
*
*Purpose:
* STRCMP compares two strings and returns an integer
* to indicate whether the first is less than the second, the two are
* equal, or whether the first is greater than the second.
*
* Comparison is done byte by byte on an UNSIGNED basis, which is to
* say that Null (0) is less than any other character (1-255).
*
*Entry:
* const char * src - string for left-hand side of comparison
* const char * dst - string for right-hand side of comparison
*
*Exit:
* returns -1 if src < dst
* returns 0 if src == dst
* returns +1 if src > dst
*
*Exceptions:
*
*******************************************************************************/

int __cdecl strcmp (
const char * src,
const char * dst
)
{
int ret = 0 ;

while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
++src, ++dst;

if ( ret < 0 )
ret = -1 ;
else if ( ret > 0 )
ret = 1 ;

return( ret );
}

maldini20040607 2009-03-07
  • 打赏
  • 举报
回复
学习了
vamking_boy 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 arong1234 的回复:]
请教人家就请教人家,说什么“相信你绝对敢兴趣”,弄得好像你要告诉别人什么东西一样

[/Quote]

那好吧,改为我向大家请教
vamking_boy 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lingyin55 的回复:]
to
直接点,比如#include <stdio.h>  .. #inlcude <conio.h> ...#include <bios.h>
等等。
我们可以直接调用里面的函数,比如 scanf() 和 printf() 函数,以及 strcmp()函数等等,可是到哪里可以找到这些函数的源代码?

这些应该被封装在dll库里面了,在工程中一般都默认会设置包含一些lib库,这些lib是对应dll的引导库,告诉程序可以去哪个dll找需要的函数。

对于为什么要那么定义那些就不大理解,也没有关注过。

[/Quote]

谢谢了
hengcai001 2009-03-07
  • 打赏
  • 举报
回复
应该是在lib或者dll文件中,LZ可参考GCC
vamking_boy 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 traceless 的回复:]
<bios.h> ?

lz用的是TC吧
[/Quote]
TC和vc9 我都有
traceless 2009-03-07
  • 打赏
  • 举报
回复
<bios.h> ?

lz用的是TC吧
xkyx_cn 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 vamking_boy 的回复:]
引用 1 楼 akirya 的回复:
如果你用的是VC9的话,在D:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src\
其他版本都差不多在这个目录下
_Cdecl一般会替换成__cdecl

那个我也找过,但还是看不懂,里面都是些声明和宏,有很多的函数声明,但就是找不到他们的源代码
[/Quote]

装的时候要选择把源代码也装上,具体在哪儿选不记得了,网上搜一下吧
traceless 2009-03-07
  • 打赏
  • 举报
回复
_Cdecl 表示通知编译器函数参数从右边压栈,由函数调用者释栈
lingyin55 2009-03-07
  • 打赏
  • 举报
回复
to
直接点,比如#include <stdio.h> .. #inlcude <conio.h> ...#include <bios.h>
等等。
我们可以直接调用里面的函数,比如 scanf() 和 printf() 函数,以及 strcmp()函数等等,可是到哪里可以找到这些函数的源代码?

这些应该被封装在dll库里面了,在工程中一般都默认会设置包含一些lib库,这些lib是对应dll的引导库,告诉程序可以去哪个dll找需要的函数。

对于为什么要那么定义那些就不大理解,也没有关注过。


to
.......
等等类似的东西,比如这个_Cdecl 就不理解,
谁能解释下 _Cdecl 这个东西,因为它是在 int 后的,怎么都看不懂........................
以及谁能提供点这方面的资料让小弟去研究下,谢谢了!!

这些最直接的办法就是上msdn查看,毕竟是微软给出的参考文档,都比较详细了。


以上是个人拙见,有不妥的地方恳请大家指出。

arong1234 2009-03-07
  • 打赏
  • 举报
回复
请教人家就请教人家,说什么“相信你绝对敢兴趣”,弄得好像你要告诉别人什么东西一样
vamking_boy 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 akirya 的回复:]
如果你用的是VC9的话,在D:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src\
其他版本都差不多在这个目录下
_Cdecl一般会替换成__cdecl
[/Quote]
那个我也找过,但还是看不懂,里面都是些声明和宏,有很多的函数声明,但就是找不到他们的源代码
qq675927952 2009-03-07
  • 打赏
  • 举报
回复
没研究过
  • 打赏
  • 举报
回复
没研究过
  • 打赏
  • 举报
回复
如果你用的是VC9的话,在D:\Program Files\Microsoft Visual Studio 9.0\VC\crt\src\
其他版本都差不多在这个目录下
_Cdecl一般会替换成__cdecl

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧