Python ʹÓÃC´úÂë——swig
Ref : http://www.swig.org/translations/chinese/tutorial.html
¼ÙÉèÄãÓÐһЩcÄãÏëÔÙ¼ÓPython.¡£¾ÙÀýÀ´ËµÓÐÕâôһ¸öÎļþexample.c
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
½Ó¿ÚÎļþ
ÏÖÔÚ£¬ÎªÁËÔö¼ÓÕâЩÎļþµ½Äãϲ»¶µÄÓïÑÔÖУ¬ÄãÐèҪдһ¸ö½Ó¿ÚÎļþ£¨interface file£©Í¶Èëµ½swigÖС£ÕâЩC functionsµÄ½Ó¿ÚÎļþ¿ÉÄÜÈçÏÂËùʾ£º
/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
½¨Á¢PythonÄ£¿é
ת»»±àÂëC³ÉPythonÄ£¿éºÜ¼òµ¥£¬Ö»ÐèÒª°´ÈçÏÂ×ö¼´¿É£¨Çë¼ûÆäËû²Ù×÷ϵͳµÄSWIG ¹²Ïí¿â°ïÖúÊֲᣩ:
unix % swig -python example.i
unix % gcc -c -fPIC
-m32
example.c example_wrap.c \
-I/usr/(local/include/python2.1)include/python2.4
unix % (ld)gcc
-shared -m32
example.o example_wrap.o -o _example.so
¹ØÓÚÒÔÉϺìÀ¶ÂÌÑÕÉ«×Ö½âÊÍ£º
1. -
Ïà¹ØÎĵµ£º
±¾ÎÄÀ´×Ô£º http://blog.pfan.cn/xiuandfang/24935.html
±êÇ©:C C ++ string String Êý¾Ý½á¹¹
C×Ö·û´®´¦Àíº¯ÊýµÄʵÏÖ
C×Ö·û´®´¦Àíº¯ÊýµÄʵÏÖ£¨Linux£©
#include <stddef.h>
char * ___strtok = NULL;
char * strcpy(char * dest,const char *src)
&nb ......
¸ù¾ÝACM¹Ù·½ÍøÕ¾3ÔÂ9ÈÕ·¢²¼µÄÏûÏ¢£¬2009ÄêͼÁé½±ÊÚÓèÁËÏÖ´úPCÖ®¸¸Charles Thacker£¬ÒÔ±íÕÃËû¶ÔµÚһ̨ÏÖ´ú¸öÈ˼ÆËã»úXerox PARC AltoµÄÏÈÇýÐÔÉè¼ÆÓëʵÏÖ£¬»¹ÓÐÔÚ¾ÖÓòÍø£¨°üÀ¨ÒÔÌ«Íø£©¡¢¶à´¦ÀíÆ÷¹¤×÷Õ¾¡¢¿ú̽¸ßËÙ»º´æÒ»ÖÂÐÔÐÒéºÍƽ°åPCµÈ·½ÃæµÄÖØ´ó·¢Ã÷ºÍ¹±Ï×£¨For the pioneering design andРrealization of the fi ......
ÕâÁ½ÌìѧϰC++ѧÀÛÁË£¬¿´Á˺ܶàµÄÍøÕ¾ÂÛ̳£¬Í»È»¸Ð¾õÃÔãÁË£¬c/c++µ½µ×ÄÜ×öÊ²Ã´ÄØ£¿ÏÖÔÚJAVAºÜÈÈ£¬Ò²ºÜºÃÕÒ¹¤×÷£¬¶øÇÒѧÆðÀ´»¹Ìý˵ºÜÈÝÒ×ÈëÃÅ¡£²»ÓÃѧ¼ÆËã»ú»ù´¡ÀàµÄ֪ʶ£¬¿ÉC/C++¾Í²»Í¬ÁË£¬Ö»Ñ§±à³Ì»¹²»ÐУ¬»¹µÃѧʲôÊý¾Ý½á¹¹£¬Ëã·¨£¬¼ÆËã»úÔÀí£¬²Ù×÷ϵͳ£¬»ã±àÓïÑÔ£¬±à³ÌÓþߵȵȣ¬ÐèÒªºÃ¶à£¬¸Ð¾õÒ» ......
Öð²½Ñݽø
f=open('/etc/motd','r')
longest=0
while True:
lineLen=len(f.readline().strip())
if not lineLen: break
if lineLen > longest:
longest=lineLen
f.close()
return longest
ÎÊÌâ£ºÒ»Ö±Õ¼Ó ......