C\C++º¯Êýµ÷Óõļ¸ÖÖ·½Ê½
µ÷Óú¯Êýʱ£¬¼ÆËã»ú³£ÓÃÕ»À´´æ´¢´«µÝ¸øº¯ÊýµÄ²ÎÊý¡£
Õ»ÊÇÒ»ÖÖÏȽøºó³öµÄÊý¾Ý½á¹¹£¬Õ»ÓÐÒ»¸ö´æ´¢Çø¡¢Ò»¸öÕ»¶¥Ö¸Õë¡£Õ»¶¥Ö¸ÕëÖ¸Ïò¶ÑÕ»ÖеÚÒ»¸ö¿ÉÓõÄÊý¾ÝÏ±»³ÆΪջ¶¥£©¡£Óû§¿ÉÒÔÔÚÕ»¶¥ÉÏ·½ÏòÕ»ÖмÓÈëÊý¾Ý£¬Õâ¸ö²Ù×÷±»³ÆΪѹջ(Push)£¬Ñ¹Õ»ÒÔºó£¬Õ»¶¥×Ô¶¯±ä³ÉмÓÈëÊý¾ÝÏîµÄλÖã¬Õ»¶¥Ö¸ÕëÒ²ËæÖ®Ð޸ġ£Óû§Ò²¿ÉÒÔ´Ó¶ÑÕ»ÖÐÈ¡×ßÕ»¶¥£¬³ÆΪµ¯³öÕ»(pop)£¬µ¯³öÕ»ºó£¬Õ»¶¥ÏµÄÒ»¸öÔªËرä³ÉÕ»¶¥£¬Õ»¶¥Ö¸ÕëËæÖ®Ð޸ġ£º¯Êýµ÷ÓÃʱ£¬µ÷ÓÃÕßÒÀ´Î°Ñ²ÎÊýѹջ£¬È»ºóµ÷Óú¯Êý£¬º¯Êý±»µ÷ÓÃÒÔºó£¬ÔÚ¶ÑÕ»ÖÐÈ¡µÃÊý¾Ý£¬²¢½øÐмÆËã¡£º¯Êý¼ÆËã½áÊøÒԺ󣬻òÕßµ÷ÓÃÕß¡¢»òÕߺ¯Êý±¾ÉíÐ޸ĶÑÕ»£¬Ê¹¶ÑÕ»»Ö¸´Ô×°¡£
ÔÚ²ÎÊý´«µÝÖУ¬ÓÐÁ½¸öÖØÒªµÄÎÊÌâ±ØÐëÒªÃ÷ȷ˵Ã÷£º
1. µ±²ÎÊý¸öÊý¶àÓÚÒ»¸öʱ£¬°´ÕÕʲô˳Ðò°Ñ²ÎÊýѹÈë¶ÑÕ»£»
2. º¯Êýµ÷Óúó£¬ÓÉËÀ´°Ñ¶ÑÕ»»Ö¸´Ô×´¡£
Ôڸ߼¶ÓïÑÔÖУ¬¾ÍÊÇͨ¹ýº¯ÊýµÄµ÷Ó÷½Ê½À´ËµÃ÷ÕâÁ½¸öÎÊÌâµÄ¡£³£¼ûµÄµ÷Ó÷½Ê½ÓУº
stdcall
cdecl
fastcall
thiscall
thiscall
naked call
ÏÂÃæ¾Í·Ö±ð½éÉÜÕ⼸ÖÖµ÷Ó÷½Ê½£º
1. stdcall
stdcallµ÷Ó÷½Ê½ÓÖ±»³ÆΪPascalµ÷Ó÷½Ê½¡£ÔÚMicrosoft C++ϵÁеÄC/C++±àÒëÆ÷ÖУ¬Ê¹ÓÃPASCALºê£¬WINAPIºêºÍCALLBACKºêÀ´Ö¸¶¨º¯ÊýµÄµ÷Ó÷½Ê½Îªstdcall¡£
stdcallµ÷Ó÷½Ê½µÄº¯ÊýÉùÃ÷Ϊ£º
int _stdcall function(int a, int b);
stdcallµÄµ÷Ó÷½Ê½Òâζ×Å£º
£¨1£© ²ÎÊý´ÓÓÒÏò×óÒ»´ÎѹÈë¶ÑÕ»
£¨2£© Óɱ»µ÷Óú¯Êý×Ô¼ºÀ´»Ö¸´¶ÑÕ»
£¨3£© º¯ÊýÃû×Ô¶¯¼ÓÇ°µ¼Ï»®Ïߣ¬ºóÃæ½ô¸ú×ÅÒ»¸ö@,Æäºó½ô¸ú×ŲÎÊýµÄ³ß´ç
ÉÏÃæÄǸöº¯Êý·Òë³É»ã±àÓïÑÔ½«±ä³É£º
push b ÏÈѹÈëµÚ¶þ¸ö²ÎÊý
push a ÔÙѹÈëµÚÒ»¸ö²ÎÊý
call function µ÷Óú¯Êý
ÔÚ±àÒëʱ£¬´Ëº¯ÊýµÄÃû×Ö±»·ÒëΪ_function@8
2. cdecl
cdeclµ÷Ó÷½Ê½ÓÖ³ÆΪCµ÷Ó÷½Ê½£¬ÊÇCÓïÑÔȱʡµÄµ÷Ó÷½Ê½£¬ËüµÄÓ﷨Ϊ£º
int function(int a, int b) // ²»¼ÓÐÞÊηû¾ÍÊÇCµ÷Ó÷½Ê½
int _cdecl function(int a, int b) // Ã÷È·Ö¸¶¨ÓÃCµ÷Ó÷½Ê½
cdeclµÄµ÷Ó÷½Ê½¾ö¶¨ÁË£º
£¨1£© ²ÎÊý´ÓÓÒÏò×óÒÀ´ÎѹÈë¶ÑÕ»
£¨2£© Óɵ÷ÓÃÕ߻ָ´¶ÑÕ»
£¨3£© º¯ÊýÃû×Ô¶¯¼ÓÇ°µ¼Ï»®Ïß
ÓÉÓÚÊÇÓɵ÷ÓÃÕßÀ´»Ö¸´¶ÑÕ»£¬Òò´ËCµ÷Ó÷½Ê½ÔÊÐíº¯ÊýµÄ²ÎÊý¸öÊýÊDz»¹Ì¶¨µÄ£¬ÕâÊÇCÓïÑÔµÄÒ»´óÌØÉ«¡£
´Ë·½Ê½µÄº¯Êý±»·ÒëΪ£º
push b // ÏÈѹÈëµÚ¶þ¸ö²ÎÊý
push a // ÔÚѹÈëµÚÒ»¸ö²ÎÊý
call funtion // µ÷Óú¯Êý
add
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
ΪʲôCÓïÑÔÒÀÈ»Èç´ËÁ÷ÐУ¿ÀúÊ·ÉÏ£¬ÓÉÓÚÖÖÖÖÔÒò£¬Òµ½çÑ¡ÔñÁËC£¬ÆäÖÐ×îÖ÷ÒªµÄÔÒò¾ÍÔÚÓÚËüµÄЧÂÊ¡£ÓÅÐãµÄC³ÌÐòµÄЧÂʼ¸ºõºÍ»ã
±àÓïÑÔ³ÌÐòÒ»Ñù¸ß£¬µ«C³ÌÐòÃ÷ÏԱȻã±àÓïÑÔ³ÌÐò¸üÒ×ÓÚ¿ª·¢¡£ºÍÐí¶àÆäËûÓïÑÔÏà±È£¬C¸øÓè³ÌÐòÔ±¸ü¶àµÄ¿ØÖÆȨ£¬Èç¿ØÖÆÊý¾ÝµÄ´æ´¢Î»Öúͳõʼ»¯¹ý³ÌµÈ¡£Cȱ·¦“°²È«Íø”ÌØÐÔ£¬ÕâËäÓÐÖúÓÚÌá¸ß ......
±¾³ÌÐò¿ÉÒÔ¶ÁÈ¡.wavÎļþ£¬È»ºó½øÐв¥·Å¡£
È·ÈÏ·½·¨£ºcat /etc/sndstat£¬Èç¹ûÏÔʾÎÞ´ËÉ豸£¬ÔòûÓа²×°Çý¶¯¡£
#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/ioctl.h>#include <stdlib.h>#include <stdio.h>#include&nbs ......
¿´µ½Õâ¸öÃæÊÔÌâ,¹À¼ÆºÜ¶à¸ÕѧCÖ¸ÕëµÄͬѧ¶¼»á¸ã´í.
void GetMemory(char *p)
{
// ´«µÝ½øÀ´µÄµÄֵʹµÃ*p==NULL
// ÕâÀïÐ޸ĵÄÊÇÕâ¸öº¯ÊýÄÚµÄÁÙʱָÕë±äÁ¿pµÄÖµ
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
// ´«µÝ½øÈ¥µÄÊÇstrµÄÖµNULL
GetMemory(str);
// ÕâÀïstrÖ¸Õë² ......