C/C++³ÌÐòÄÚ´æ·ÖÅäÏê½â
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö
1¡¢Õ»Çø£¨stack£©— ³ÌÐòÔËÐÐʱÓɱàÒëÆ÷×Ô¶¯·ÖÅ䣬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½ÀàËÆÓÚÊý¾Ý½á¹¹ÖеÄÕ»¡£³ÌÐò½áÊøʱÓɱàÒëÆ÷×Ô¶¯ÊÍ·Å¡£
2¡¢¶ÑÇø£¨heap£© — ÔÚÄڴ濪±ÙÁíÒ»¿é´æ´¢ÇøÓò¡£Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å£¬ Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøʱ¿ÉÄÜÓÉOS»ØÊÕ ¡£×¢ÒâËüÓëÊý¾Ý½á¹¹ÖеĶÑÊÇÁ½»ØÊ£¬·ÖÅ䷽ʽµ¹ÊÇÀàËÆÓÚÁ´±í£¬ºÇºÇ¡£
3¡¢È«¾ÖÇø£¨¾²Ì¬Çø£©£¨static£©—±àÒëÆ÷±àÒëʱ¼´·ÖÅäÄڴ档ȫ¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿µÄ´æ´¢ÊÇ·ÅÔÚÒ»¿éµÄ£¬³õʼ»¯µÄ È«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿ÔÚÒ»¿éÇøÓò£¬ δ³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍδ³õʼ»¯µÄ¾²Ì¬±äÁ¿ÔÚÏàÁÚµÄÁíÒ»¿éÇøÓò¡£ - ³ÌÐò½áÊøºóÓÉϵͳÊÍ·Å
4¡¢ÎÄ×Ö³£Á¿Çø —³£Á¿×Ö·û´®¾ÍÊÇ·ÅÔÚÕâÀïµÄ¡£ ³ÌÐò½áÊøºóÓÉϵͳÊÍ·Å
5¡¢³ÌÐò´úÂëÇø—´æ·Åº¯ÊýÌåµÄ¶þ½øÖÆ´úÂë¡£
Àý×Ó³ÌÐò
ÕâÊÇÒ»¸öÇ°±²Ð´µÄ£¬·Ç³£Ïêϸ
//main.cpp
int a = 0; È«¾Ö³õʼ»¯Çø
char *p1; È«¾Öδ³õʼ»¯Çø
main()
{
int b;// Õ»
char s[] = "abc"; //Õ»
char *p2; //Õ»
char *p3 = "123456"; //"123456\0"ÔÚ³£Á¿Çø£¬p3ÔÚÕ»ÉÏ¡£
static int c =0£» //È«¾Ö£¨¾²Ì¬£©³õʼ»¯Çø
p1 = (char *)malloc(10);
p2 = (char *)malloc(20);
//·ÖÅäµÃÀ´µÃ10ºÍ20×Ö½ÚµÄÇøÓò¾ÍÔÚ¶ÑÇø¡£
strcpy(p1, "123456"); //123456\0·ÅÔÚ³£Á¿Çø£¬±àÒëÆ÷¿ÉÄܻὫËüÓëp3ËùÖ¸ÏòµÄ"123456"ÓÅ»¯³ÉÒ»¸öµØ·½¡£
}
===============
CÓïÑÔ³ÌÐòµÄÄÚ´æ·ÖÅ䷽ʽ
1.ÄÚ´æ·ÖÅ䷽ʽ
ÄÚ´æ·ÖÅ䷽ʽÓÐÈýÖÖ£º
[1]´Ó¾²Ì¬´æ ´¢ÇøÓò·ÖÅä¡£ÄÚ´æÔÚ³ÌÐò±àÒëµÄʱºò¾ÍÒѾ·ÖÅäºÃ£¬Õâ¿éÄÚ´æÔÚ³ÌÐòµÄÕû¸öÔËÐÐÆڼ䶼´æÔÚ¡£ÀýÈçÈ«¾Ö±äÁ¿£¬static±äÁ¿¡£
[2]ÔÚÕ»ÉÏ´´½¨¡£ ÔÚÖ´Ðк¯Êýʱ£¬º¯ÊýÄÚ¾Ö²¿±äÁ¿µÄ´æ´¢µ¥Ôª¶¼¿ÉÒÔÔÚÕ»ÉÏ´´½¨£¬º¯ÊýÖ´ÐнáÊøʱÕâЩ´æ´¢µ¥Ôª×Ô¶¯±»ÊÍ·Å¡£Õ»ÄÚ´æ·ÖÅäÔËËãÄÚÖÃÓÚ´¦ÀíÆ÷µÄÖ¸ÁÖУ¬Ð§Âʺܸߣ¬µ« ÊÇ·ÖÅäµÄÄÚ´æÈÝÁ¿ÓÐÏÞ¡£
[3]´Ó¶ÑÉÏ·ÖÅ䣬Òà³Æ¶¯Ì¬ÄÚ´æ·ÖÅä¡£³ÌÐòÔÚÔËÐеÄʱºòÓÃmalloc»ònewÉêÇëÈÎÒâ¶àÉÙµÄÄڴ棬³ÌÐòÔ±×Ô¼º¸ºÔðÔÚ ºÎʱÓÃfree»òdeleteÊÍ·ÅÄÚ´æ¡£¶¯Ì¬ÄÚ´æµÄÉú´æÆÚÓɳÌÐòÔ±¾ö¶¨£¬Ê¹Ó÷dz£Áé»î£¬µ«Èç¹ûÔÚ¶ÑÉÏ·ÖÅäÁ˿ռ䣬¾ÍÓÐÔðÈλØÊÕËü£¬·ñÔòÔËÐеijÌÐò»á³öÏÖÄÚ ´æй©£¬Æµ·±µØ·ÖÅäºÍÊͷŲ»Í¬´óСµÄ¶Ñ¿Õ¼ä½«»á²úÉú¶ÑÄÚËé¿é¡£
2.³ÌÐòµÄÄÚ´æ¿Õ¼ä
Ò»¸ö³ÌÐò½«²Ù×÷ ϵͳ·ÖÅä¸øÆäÔËÐеÄÄÚ´æ¿é·ÖΪ4¸öÇøÓò£¬ÈçÏÂͼËùʾ¡£
Ò»¸öÓÉC/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö,
1¡¢Õ»Çø£¨stack£©
Ïà¹ØÎĵµ£º
Ò»Sun Studio ¼ò½é
Sun Studio ÊÇ Solaris/OpenSolaris ²Ù×÷ϵͳÉϵÄÊ×Ñ¡¿ª·¢»·¾³¡£Ëü°üº¬²¢ÓÅ»¯ÁË C ¡¢ C++ ¼° Fortran ±àÒëÆ÷£¬¶øÇÒÈÚÈëÁËÒµ½çÁìÏ鵀 IDE ºÍÐÔÄܵ÷ÊÔ¼¼Êõ¡£Ëæ×ÅÈíÓ²¼þ¼¼Êõ·¢Õ¹¹ØϵµÄµ÷Õû£¬¿ª·¢¶à´¦ÀíÆ÷ºÍ¶àÏß³ÌÓ¦ÓõÄÖØÒªÐÔÕýÈÕÒæÍ»³ö£¬¶ø Sun StudioÔÚ¿ª·¢¶àÏ̳߳ÌÐò£¨Ó ......
C++²»¶¨²ÎÊýµÄÓ÷¨ £¨CÀàËÆ£©
2009-11-19 15:41
/*
va_list vl; //¶¨ÒåÒ»¸öÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿(Ò»¸ö...Ö¸Õë)
va_start(vl,first_param); //°ÑÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿³õʼ»¯
va_arg(vl,mode); //»ñÈ¡ÏÂÒ»¸ö²ÎÊý,²ÎÊýÀàÐÍÓɵڶþ¸ö²ÎÊýÖ¸¶¨,µÚ¶þ¸ö²ÎÊýÓÃÓÚÔÚva_argÄÚ²¿½øÐгߴç¼ÆËã,ÒÔ±ãÕÒµ½ÏÂÒ»¸ö²ÎÊý
va_end(vl); //½áÊø
......
http://demonstyle.blog.163.com/blog/static/13143429020091010112159/
C/C++ ºêÏê½â
ic/c++ 2009-11-10 01:12:15 ÔĶÁ18 ÆÀÂÛ0 ×ֺţº´óÖÐС
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐÍ ......
http://www.diybl.com/course/3_program/c++/cppjs/20090403/163906.html
CºÍC++»ìºÏ±à³Ì(__cplusplus Óë external "c" µÄʹÓÃ)
www.diybl.com¡¡Ê±¼ä£º2009-04-03¡¡×÷Õß:ÄäÃû ±à¼:sky µã»÷£º¡¡124 [ÆÀÂÛ]
µÚÒ»ÖÖÀí½â
±ÈÈç˵ÄãÓÃC++¿ª·¢ÁËÒ»¸öDLL¿â£¬ÎªÁËÄܹ»ÈÃCÓïÑÔÒ²Äܹ»µ÷ÓÃÄãµÄDLLÊä³ö(Export)µÄº¯Êý£¬ÄãÐèÒªÓÃexte ......
ÓÃvc6н¨ÁËÒ»¸öwin32µÄ¿ØÖÆ̨³ÌÐò£¬µ÷ÊÔÒ»¸öÖ±½Ó²åÈëÅÅÐòµÄС³ÌÐò£¬Îļþ¶¨ÒåΪ.cÎļþ£¬¶ø²»ÊÇÒ»°ãʹÓõÄ.cppÎļþ£¬´úÂë¶ÎÈçÏ£º
#include <stdio.h>
void inst(int* x,int n)
{
int i,j,t;
for(i=1; i<n; i++) /* i±íʾ²åÈë´ÎÊý£¬¹²½øÐÐn-1´Î²åÈë*/
{
t = x[i];
for(j=i-1; j> ......