真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

c語(yǔ)言庫(kù)函數(shù)源碼 c語(yǔ)言庫(kù)函數(shù)大全pdf

C語(yǔ)言庫(kù)函數(shù)qsort源代碼

void __fileDECL qsort (

創(chuàng)新互聯(lián)公司始終堅(jiān)持【策劃先行,效果至上】的經(jīng)營(yíng)理念,通過(guò)多達(dá)十余年累計(jì)超上千家客戶的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的全網(wǎng)整合營(yíng)銷推廣解決方案,現(xiàn)已廣泛運(yùn)用于各行各業(yè)的客戶,其中包括:建筑動(dòng)畫(huà)等企業(yè),備受客戶贊譽(yù)。

void *base,

size_t num,

size_t width,

int (__fileDECL *comp)(const void *, const void *)

)

#endif /* __USE_CONTEXT */

{

char *lo, *hi; /* ends of sub-array currently sorting */

char *mid; /* points to middle of subarray */

char *loguy, *higuy; /* traveling pointers for partition step */

size_t size; /* size of the sub-array */

char *lostk[STKSIZ], *histk[STKSIZ];

int stkptr; /* stack for saving sub-array to be processed */

/* validation section */

_VALIDATE_RETURN_VOID(base != NULL || num == 0, EINVAL);

_VALIDATE_RETURN_VOID(width 0, EINVAL);

_VALIDATE_RETURN_VOID(comp != NULL, EINVAL);

if (num 2)

return; /* nothing to do */

stkptr = 0; /* initialize stack */

lo = (char *)base;

hi = (char *)base + width * (num-1); /* initialize limits */

/* this entry point is for pseudo-recursion calling: setting

lo and hi and jumping to here is like recursion, but stkptr is

preserved, locals aren't, so we preserve stuff on the stack */

recurse:

size = (hi - lo) / width + 1; /* number of el's to sort */

/* below a certain size, it is faster to use a O(n^2) sorting method */

if (size = CUTOFF) {

__SHORTSORT(lo, hi, width, comp, context);

}

else {

/* First we pick a partitioning element. The efficiency of the

algorithm demands that we find one that is approximately the median

of the values, but also that we select one fast. We choose the

median of the first, middle, and last elements, to avoid bad

performance in the face of already sorted data, or data that is made

up of multiple sorted runs appended together. Testing shows that a

median-of-three algorithm provides better performance than simply

picking the middle element for the latter case. */

mid = lo + (size / 2) * width; /* find middle element */

/* Sort the first, middle, last elements into order */

if (__COMPARE(context, lo, mid) 0) {

swap(lo, mid, width);

}

if (__COMPARE(context, lo, hi) 0) {

swap(lo, hi, width);

}

if (__COMPARE(context, mid, hi) 0) {

swap(mid, hi, width);

}

/* We now wish to partition the array into three pieces, one consisting

of elements = partition element, one of elements equal to the

partition element, and one of elements than it. This is done

below; comments indicate conditions established at every step. */

loguy = lo;

higuy = hi;

/* Note that higuy decreases and loguy increases on every iteration,

so loop must terminate. */

for (;;) {

/* lo = loguy hi, lo higuy = hi,

A[i] = A[mid] for lo = i = loguy,

A[i] A[mid] for higuy = i hi,

A[hi] = A[mid] */

/* The doubled loop is to avoid calling comp(mid,mid), since some

existing comparison funcs don't work when passed the same

value for both pointers. */

if (mid loguy) {

do {

loguy += width;

} while (loguy mid __COMPARE(context, loguy, mid) = 0);

}

if (mid = loguy) {

do {

loguy += width;

} while (loguy = hi __COMPARE(context, loguy, mid) = 0);

}

/* lo loguy = hi+1, A[i] = A[mid] for lo = i loguy,

either loguy hi or A[loguy] A[mid] */

do {

higuy -= width;

} while (higuy mid __COMPARE(context, higuy, mid) 0);

/* lo = higuy hi, A[i] A[mid] for higuy i hi,

either higuy == lo or A[higuy] = A[mid] */

if (higuy loguy)

break;

/* if loguy hi or higuy == lo, then we would have exited, so

A[loguy] A[mid], A[higuy] = A[mid],

loguy = hi, higuy lo */

swap(loguy, higuy, width);

/* If the partition element was moved, follow it. Only need

to check for mid == higuy, since before the swap,

A[loguy] A[mid] implies loguy != mid. */

if (mid == higuy)

mid = loguy;

/* A[loguy] = A[mid], A[higuy] A[mid]; so condition at top

of loop is re-established */

}

/* A[i] = A[mid] for lo = i loguy,

A[i] A[mid] for higuy i hi,

A[hi] = A[mid]

higuy loguy

implying:

higuy == loguy-1

or higuy == hi - 1, loguy == hi + 1, A[hi] == A[mid] */

/* Find adjacent elements equal to the partition element. The

doubled loop is to avoid calling comp(mid,mid), since some

existing comparison funcs don't work when passed the same value

for both pointers. */

higuy += width;

if (mid higuy) {

do {

higuy -= width;

} while (higuy mid __COMPARE(context, higuy, mid) == 0);

}

if (mid = higuy) {

do {

higuy -= width;

} while (higuy lo __COMPARE(context, higuy, mid) == 0);

}

/* OK, now we have the following:

higuy loguy

lo = higuy = hi

A[i] = A[mid] for lo = i = higuy

A[i] == A[mid] for higuy i loguy

A[i] A[mid] for loguy = i hi

A[hi] = A[mid] */

/* We've finished the partition, now we want to sort the subarrays

[lo, higuy] and [loguy, hi].

We do the smaller one first to minimize stack usage.

We only sort arrays of length 2 or more.*/

if ( higuy - lo = hi - loguy ) {

if (lo higuy) {

lostk[stkptr] = lo;

histk[stkptr] = higuy;

++stkptr;

} /* save big recursion for later */

if (loguy hi) {

lo = loguy;

goto recurse; /* do small recursion */

}

}

else {

if (loguy hi) {

lostk[stkptr] = loguy;

histk[stkptr] = hi;

++stkptr; /* save big recursion for later */

}

if (lo higuy) {

hi = higuy;

goto recurse; /* do small recursion */

}

}

}

/* We have sorted the array, except for any pending sorts on the stack.

Check if there are any, and do them. */

--stkptr;

if (stkptr = 0) {

lo = lostk[stkptr];

hi = histk[stkptr];

goto recurse; /* pop subarray from stack */

}

else

return; /* all subarrays done */

}

VC 6.0的C語(yǔ)言庫(kù)函數(shù)的源代碼可以在哪找到?

深入printf

/***

*printf.c - print formatted

*

* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.

*

*Purpose:

* defines printf() - print formatted data

*

*******************************************************************************/

#include

#include

#include

#include

#include

#include

#include

/***

*int printf(format, ...) - print formatted data

*

*Purpose:

* Prints formatted data on stdout using the format string to

* format data and getting as many arguments as called for

* Uses temporary buffering to improve efficiency.

* _output does the real work here

*

*Entry:

* char *format - format string to control data format/number of arguments

* followed by list of arguments, number and type controlled by

* format string

*

*Exit:

* returns number of characters printed

*

*Exceptions:

*

*******************************************************************************/

int __cdecl printf (

const char *format,

...

)

/*

* stdout ''PRINT'', ''F''ormatted

*/

{

va_list arglist;

int buffing;

int retval;

va_start(arglist, format);

_ASSERTE(format != NULL);//斷言宏。如果輸出格式字符串指針為空,則在DEBUG版下斷言,報(bào)告錯(cuò)誤。

_lock_str2(1, stdout);

buffing = _stbuf(stdout);//stdout:指定輸出到屏幕

retval = _output(stdout,format,arglist);

_ftbuf(buffing, stdout);

_unlock_str2(1, stdout);

return(retval);

}

以上為printf()的源代碼

1、從含有可選參數(shù)函數(shù)中獲得可選參數(shù),以及操作這些參數(shù)

typedef char *va_list;

void va_start( va_list arg_ptr, prev_param );

type va_arg( va_list arg_ptr, type );

void va_end( va_list arg_ptr );

假定函數(shù)含有一個(gè)必選參數(shù)和多個(gè)可選參數(shù),必選參數(shù)聲明為普通數(shù)據(jù)類型,且能通過(guò)參數(shù)名來(lái)獲得該變量的值??蛇x參數(shù)通過(guò)宏va_start、va_arg和va_end(定義在stdarg.h或varargs.h中)來(lái)進(jìn)行操作,即通過(guò)設(shè)置指向第一個(gè)可選參數(shù)指針、返回當(dāng)前參數(shù)、在返回參數(shù)后重新設(shè)置指針來(lái)操作所有的可選參數(shù)。

va_start:為獲取可變數(shù)目參數(shù)的函數(shù)的參數(shù)提供一種便捷手段。設(shè)置arg_ptr為指向傳給函數(shù)參數(shù)列表中的第一個(gè)可選參數(shù)的指針,且該參數(shù)必須是va_list類型。prev_param是在參數(shù)列表中第一個(gè)可選參數(shù)前的必選參數(shù)。

va_arg:返回由arg_ptr所指向的參數(shù)的值,且自增指向下一個(gè)參數(shù)的地址。type為當(dāng)前參數(shù)的類型,用來(lái)計(jì)算該參數(shù)的長(zhǎng)度,確定下一個(gè)參數(shù)的起始位置。它可以在函數(shù)中應(yīng)用多次,直到得到函數(shù)的所有參數(shù)為止,但必須在宏va_start后面調(diào)用。

va_end:在獲取所有的參數(shù)后,設(shè)置指針arg_ptr為NULL。

下面舉例說(shuō)明:

#include

#include

int average( int first, ... );

void main( void )

{

/* Call with 3 integers (-1 is used as terminator). */

printf( "Average is: %d\n", average( 2, 3, 4, -1 ) );

/* Call with 4 integers. */

printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) );

/* Call with just -1 terminator. */

printf( "Average is: %d\n", average( -1 ) );

}

int average( int first, ... )

{

int count = 0, sum = 0, i = first;

va_list marker;

va_start( marker, first ); /* Initialize variable arguments. */

while( i != -1 )

{

sum += i;

count++;

i = va_arg( marker, int);

}

va_end( marker ); /* Reset variable arguments. */

return( sum ? (sum / count) : 0 );

}

返回值為:

Average is: 3

Average is: 8

Average is: 0

綜上所述,在printf()函數(shù)中,可以只輸出一個(gè)字符串,也可按照一定的形式輸出含有多個(gè)可選參數(shù)的字符串信息。因此,首先就要通過(guò)這些宏來(lái)獲取所有的可選參數(shù)。在上面的源碼可以看出printf()中,只使用了宏at_start,將可選參數(shù)的首地址賦給了arglist。

2、鎖定字符串及輸出字符串到屏幕

#define _lock_str2(i,s) _lock_file2(i,s)

void __cdecl _lock_file2(int, void *);

#define _unlock_str2(i,s) _unlock_file2(i,s)

void __cdecl _unlock_file2(int, void *);

int __cdecl _stbuf(FILE *);

void __cdecl _ftbuf(int, FILE *);

int __cdecl _output(FILE *, const char *, va_list);

在output函數(shù)中,讀取格式字符串中的每一個(gè)字符,然后對(duì)其進(jìn)行處理,處理方式根據(jù)每一個(gè)字符所代表的意義來(lái)進(jìn)行,如:普通字符直接利用函數(shù)WRITE_CHAR(ch, charsout);輸出到控制臺(tái)。

其中的主要部分是對(duì)轉(zhuǎn)換說(shuō)明符(d,c,s,f)的處理,現(xiàn)在將對(duì)其中的部分代碼進(jìn)行詳細(xì)說(shuō)明,這里只說(shuō)明最基本的轉(zhuǎn)換說(shuō)明符,對(duì)這些須基本的轉(zhuǎn)換說(shuō)明符進(jìn)行修飾的修飾符,程序中單獨(dú)進(jìn)行處理。下面是函數(shù)output()(output.c)部分源代碼:

case ST_TYPE:

//表示當(dāng)前處理的字符的類型為轉(zhuǎn)換說(shuō)明符。

...

switch (ch) {

//下面對(duì)參數(shù)的獲取都是利用宏va_arg( va_list arg_ptr, type );來(lái)進(jìn)行的。

case ''c'': {

//從參數(shù)表中獲取單個(gè)字符,輸出到緩沖字符串中,此時(shí),type=int

buffer[0] = (char) get_int_arg(argptr); /* get char to print */

text = buffer;

textlen = 1; /* print just a single character */

}

break;

case ''s'': {

//從參數(shù)表中獲取字符串,輸出到緩沖字符串中,此時(shí),type=char*

int i;

char *p; /* temps */

text = get_ptr_arg(argptr);

...

}

break;

case ''w'': {

//對(duì)寬字符進(jìn)行處理

...

} /* case ''w'' */

break;

...

case ''e'':

case ''f'':

case ''g'': {

//對(duì)浮點(diǎn)數(shù)進(jìn)行操作

...

#if !LONGDOUBLE_IS_DOUBLE

/* do the conversion */

if (flags FL_LONGDOUBLE) {

_cldcvt((LONGDOUBLE*)argptr, text, ch, precision, capexp);

va_arg(argptr, LONGDOUBLE);

//對(duì)長(zhǎng)雙精度型進(jìn)行處理,此時(shí),type=long double

}

else

#endif /* !LONGDOUBLE_IS_DOUBLE */

{

//對(duì)雙精度型進(jìn)行處理,此時(shí),type=double

_cfltcvt((DOUBLE*)argptr, text, ch, precision, capexp);

va_arg(argptr, DOUBLE);

}

...

break;

//對(duì)整型變量處理

case ''d'':

case ''i'':

...

goto COMMON_INT;

case ''u'':

radix = 10;

goto COMMON_INT;

case ''p'':

...

goto COMMON_INT;

case ''o'':

...

注:對(duì)于浮點(diǎn)型double和long double,有相應(yīng)的轉(zhuǎn)換說(shuō)明符(%f表示雙精度型,%lf表示長(zhǎng)雙精度型),而float卻沒(méi)有。其中的原因是,在KRC下,float值用于表達(dá)式或用作參數(shù)前,會(huì)自動(dòng)轉(zhuǎn)換成double類型。而ANSI C一般不會(huì)自動(dòng)把float轉(zhuǎn)換成double。有些程序已假定其中的float參數(shù)會(huì)被轉(zhuǎn)換成double,為了保護(hù)大量這樣的程序,所有printf()函數(shù)的float參數(shù)還是被自動(dòng)轉(zhuǎn)換成double型。因此,在KRC或ANSI C下,都無(wú)需用特定的轉(zhuǎn)換說(shuō)明符來(lái)顯示float型。

綜上所述,轉(zhuǎn)換說(shuō)明符必須與待打印字符的類型。通常,用戶有種選擇。例如,如要打印一個(gè)int類型的值。則只可以使用%d,%x或%o。所有這些說(shuō)明符都表示要打印一個(gè)int類型的值;它們只不過(guò)提供了一個(gè)數(shù)值的幾種不同表示。類似一,可以用%f、%g和%e來(lái)表示double類型的值。但如果轉(zhuǎn)換說(shuō)明與類型不匹配,將會(huì)出現(xiàn)意想不到的結(jié)果。為什么呢?問(wèn)題就在于C向函數(shù)傳遞信息的方式。

這個(gè)失敗的根本細(xì)節(jié)與具體實(shí)現(xiàn)相關(guān)。它決定了系統(tǒng)中的參數(shù)以何方式傳遞。函數(shù)調(diào)用如下:

float n1;

double n2;

long n3;

long n4;

...

printf("%ld,%ld,%ld,%ld",n1,n2,n3,n4);

這個(gè)調(diào)用告訴計(jì)算機(jī),要把變量n1,n2,n3和n4的值交給計(jì)算機(jī),它把這些變量放進(jìn)稱作棧(stack)的內(nèi)存區(qū)域中,來(lái)完成這一任務(wù)。計(jì)算機(jī)把這些值放進(jìn)棧中,其根據(jù)是變量的類型而不是轉(zhuǎn)換說(shuō)明符,比如n1,把8個(gè)字節(jié)放入棧中(float被轉(zhuǎn)換成double),類似地,為n2放了8字節(jié),其后給n3和n4各放了4個(gè)字節(jié)。接著,控制的對(duì)象轉(zhuǎn)移到printf();此函數(shù)從棧中讀數(shù),不過(guò)在這一過(guò)程中,它是在轉(zhuǎn)換說(shuō)明符的指導(dǎo)下,讀取數(shù)值的。說(shuō)明符%ld指定printf()應(yīng)讀4個(gè)字節(jié)(va_arg( va_list arg_ptr, type )中type=long),因此printf()讀入棧中的4個(gè)字節(jié),作為它的第一個(gè)值。但是這只是n1的前半部分,這個(gè)值被看成一個(gè)long整數(shù)。下一個(gè)說(shuō)明符%ld讀入4個(gè)字節(jié),這正是n1的后半部分,這個(gè)值被看成第二個(gè)long整數(shù)。類似地,第三、第四次又讀入n2的前后兩部分。因此,盡管我們對(duì)n3和n4使用了正確的說(shuō)明符,printf()仍然會(huì)產(chǎn)生錯(cuò)誤。

這里也可以下載

如何看c語(yǔ)言標(biāo)準(zhǔn)庫(kù)函數(shù)的源代碼?

很遺憾,標(biāo)準(zhǔn)庫(kù)中的函數(shù)結(jié)合了系統(tǒng),硬件等的綜合能力,是比較近機(jī)器的功能實(shí)現(xiàn),所以大部分是用匯編完成的,而且已經(jīng)導(dǎo)入到了lib和dll里了,就是說(shuō),他們已經(jīng)被編譯好了,似乎沒(méi)有代碼的存在了.

能看到的也只有dll中有多少函數(shù)被共享.

第三方可能都是dll,因?yàn)樯厦嬉舱f(shuō)了,dll是編譯好的,只能看到成品,就可以隱藏代碼,保護(hù)自己的知識(shí)產(chǎn)權(quán),同時(shí)也是病毒的歸宿...... 當(dāng)然,除了DLL的確還存在一種東西,插件程序~~~

如何查看C語(yǔ)言,內(nèi)庫(kù)的源代碼?

如果是“.cpp”文件并且有VC++的環(huán)境,可直接雙擊文件打開(kāi)或者先打開(kāi)編譯環(huán)境,在新建一個(gè)控制臺(tái)下的源文件,然后,選擇file菜單下的open找到你的文件導(dǎo)入,然后編譯運(yùn)行;如果是其他格式的,如txt文件,也可先打開(kāi)編譯環(huán)境,新建一個(gè)控制臺(tái)下的源文件,然后直接復(fù)制粘貼進(jìn)去,然后編譯運(yùn)行;

便已運(yùn)行的操作如圖:


新聞標(biāo)題:c語(yǔ)言庫(kù)函數(shù)源碼 c語(yǔ)言庫(kù)函數(shù)大全pdf
新聞來(lái)源:http://weahome.cn/article/dogjsch.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部