Pipe is a worm hole connecting C and C++
In C programming language, the observer design pattern is implemented with function pointer (aka callback function). But in Qt library, it introduces signal and slot. How to link a callback function from the C callback function to the C++ siganl and slot is a problem I encounter. Call back function can only be static, but signal and slot can not. There are some triky way to pretend a non-static function to a static function. But the easiest way is to use pipe. the callback function create a pipe and do the read operation, while the siganl function wait for and read at the other end of the pipe.
The pipe is like a worm hole connecting C and C++, two different time and space. How cool!
Ïà¹ØÎĵµ£º
1¡¢ ¾³£¿´¼ûreturn EXIT_SUCCESS»òreturn EXIT_FAILURE£¬µ«¶¼²»ÖªÕâÁ½¸öÀ´×Ժ䦣¬ÏÖÔÚ²ÅÖªÔÀ´stdlib.h¶¨ÒåÁËEXIT_SUCCESSºÍEXIT_FAILURE·ûºÅ¡£
ÔÚstdlib.hÍ·ÎļþÀ
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
& ......
Ò». ÔÚcÖзÖΪÕ⼸¸ö´æ´¢Çø
1.Õ» - ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å
2.¶Ñ - Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å£¬Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøÊ±¿ÉÄÜÓÉOS»ØÊÕ
3.È«¾ÖÇø£¨¾²Ì¬Çø£©£¬È«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿µÄ´æ´¢ÊÇ·ÅÔÚÒ»¿éµÄ£¬³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿ÔÚÒ»¿éÇøÓò£¬Î´³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍδ³õʼ»¯µÄ¾²Ì¬±äÁ¿ÔÚÏàÁÚµÄÁíÒ»¿éÇøÓò¡£- ³ÌÐò½áÊøÊÍ·Å
4.Á ......
´òÓ¡×Ô¼ºµÄÒ»¶ÎƯÁÁC³ÌÐò
#include <stdio.h>
int main()
{
char *p ="#include <stdio.h>%c int main(){char *p=%c%s%c; printf(p, 10, 34, p, 34);}";
printf(p, 10, 34, p, 34);
} ......
1.½éÉÜÒ»ÏÂSTL£¬Ïêϸ˵Ã÷STLÈçºÎʵÏÖvector.
Answer£º
STL £¨±ê׼ģ°æ¿â£¬Standard Template Library.ËüÓÉÈÝÆ÷Ëã·¨µü´úÆ÷×é³É¡£
STLÓÐÒÔϵÄһЩÓŵ㣺¿ÉÒÔ·½±ãÈÝÒ×µØÊµÏÖËÑË÷Êý¾Ý»ò¶ÔÊý¾ÝÅÅÐòµÈһϵÁеÄËã·¨£»µ÷ÊÔ³ÌÐòʱ¸ü¼Ó°²È« ºÍ·½±ã£»¼´Ê¹ÊÇÈËÃÇÓÃSTLÔÚ ......
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå·½·¨£¬ÓÐÁ½ÖÖ£ºÒ»ÖÖÊDZê×¼µÄ·½·¨£»Ò»ÖÖÊÇÃÉÆ·¨¡£
µÚÒ»ÖÖ£¬±ê×¼·½·¨£º
{
·ÖÎö£ºº¯ÊýÖ¸ÕëÊý×éÊÇÒ»¸öÆäÔªËØÊǺ¯ÊýÖ¸ÕëµÄÊý×é¡£ÄÇôҲ¾ÍÊÇ˵£¬´ËÊý¾Ý½á¹¹ÊÇÊÇÒ»¸öÊý×飬ÇÒÆäÔªËØÊÇÒ»¸öÖ¸Ïòº¯ÊýÈë¿ÚµØÖ·µÄÖ¸Õë¡£
¸ù¾Ý·ÖÎö£ºÊ×ÏÈ˵Ã÷ÊÇÒ»¸öÊý×飺Êý×éÃû[]
Æä´Î£¬ÒªËµÃ ......