Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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!


Ïà¹ØÎĵµ£º

ANSI C —— ¸ñʽ»¯Êä³ö

¡¾Ô­ÐÍ¡¿
printf("<¸ñʽ»¯×Ö·û´®>
", <²ÎÁ¿±í>
);
 
int printf
(const char *format, ...);
int fprintf
(FILE *stream, const char *format, ...);
int sprintf
(char *str, const char *format, ...);
int snprintf
(char *str, size_t size, const char *format, ...);
vp ......

Exper C Programming ÁãÁãɢɢ

1.
¹ØÓÚchar* ºÍconst char*ÒÔ¼°char**ºÍconst char**·Ö±ð×÷Ϊʵ²ÎºÍÐβεÄÎÊÌâ
´«ÖµÊµ¼ÊÉÏÊÇÀàËÆÓÚ¸³ÖµµÄ¡£
Á½¸ö²Ù×÷Êý¶¼ÊÇÖ¸ÏòÏÞ¶¨·û»òÎÞÏÞ¶¨·ûµÄÏàÈÝÀàÐ͵ÄÖ¸Õ룬×ó±ßÖ¸ÕëËùÖ¸ÏòµÄÀàÐͱØÐë¾ßÓÐÓÒ±ßÖ¸ÕëËùÖ¸ÏòÀàÐ͵ÄÈ«²¿ÏÞ¶¨·û¡£ ......

C/C++ ÄÚ´æ¿Õ¼ä·ÖÅä


Ò». ÔÚcÖзÖΪÕ⼸¸ö´æ´¢Çø
1.Õ» - ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å
2.¶Ñ - Ò»°ãÓɳÌÐòÔ±·ÖÅäÊÍ·Å£¬Èô³ÌÐòÔ±²»ÊÍ·Å£¬³ÌÐò½áÊøÊ±¿ÉÄÜÓÉOS»ØÊÕ
3.È«¾ÖÇø£¨¾²Ì¬Çø£©£¬È«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿µÄ´æ´¢ÊÇ·ÅÔÚÒ»¿éµÄ£¬³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍ¾²Ì¬±äÁ¿ÔÚÒ»¿éÇøÓò£¬Î´³õʼ»¯µÄÈ«¾Ö±äÁ¿ºÍδ³õʼ»¯µÄ¾²Ì¬±äÁ¿ÔÚÏàÁÚµÄÁíÒ»¿éÇøÓò¡£- ³ÌÐò½áÊøÊÍ·Å
4.Á ......

LinuxÏÂC¿ª·¢Ö®gcc,gdbµÄʹÓÃ

gcc£¬gdbµÄʹÓÃ
×÷Õߣºzccst
 
ÉÏÖÜÎåÔÚͼÊé¹Ý½èÁËÒ»±¾¡¶LinuxÈí¼þ¹¤³Ìʦ£¨CÓïÑÔ£©ÊµÓý̡̳·£¬ÈÃÎÒÊÕ»ñÁ¼¶à¡£²»½ö½öÊÇÊéÖеÄ֪ʶ£¬»¹ÓжÔ֪ʶÌåϵºÍ¼Ü¹¹ÈÏʶµÄÉîÈë¡£
 
LinuxÏÂC¿ª·¢£º
1£¬gcc,gdbµÄʹÓá£
2£¬MakefileÎļþµÄ±àд¡£
3£¬ÏµÍ³º¯ÊýµÄʹÓÃ
4£¬Îļþ²Ù×÷
5£¬´®ÐÐͨÐÅ
6£¬½ø³Ì¿ØÖÆ
7£¬½ø³Ì¼ ......

´òÓ¡×Ô¼ºµÄÒ»¶ÎƯÁÁC³ÌÐò

´òÓ¡×Ô¼ºµÄÒ»¶ÎƯÁÁ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);
} ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ