易截截图软件、单文件、免安装、纯绿色、仅160KB

C: 面向对象(3)

以下代码演示如何用C来模拟多态。gcc版本:3.4.4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#ifndef class
        #define class struct
#endif
#ifndef private
        #define private
#endif
#ifndef public
        #define public
#endif
#ifndef protected
        #define protected
#endif
#ifndef bool
        #define bool int
#endif
#ifndef true
        #define true 1
#endif
#ifndef false
        #define false 0
#endif
class Parent{
      //private members
      private class Parent *this;
      private size_t len;
     
      //public members
      public size_t (*length)(class Parent *this);
      public void (*construct)(class Parent *this);
      public void (*print)(class Parent *this);
      public void (*destruct)(class Parent *this);
};
class Son{
      //private members
      private class Son *this;
      //inherit
      private class Parent *inherit;
     
      //public members
      public size_t (*length)(class Son *this);
      public bool (*construct)(class Son *this);
      public void (*print)(class Son *this);
      public void (*destruct)(class Son *this);
};
//forward declaration
void ParentConstruct(class Parent *this);
void ParentPr


相关文档:

C变参函数的实现机制

C的变参问题与print函数的实现
我们在C语言编程中会遇到一些参数个数可变的函数,例如printf() 这个函数,它的定义是这样的: int printf( const char* format, ...); 
它除了有一个参数format固定以外,后面跟的参数的个数和类型是可变的,例如我们可以有以下不同的调用方法:
   printf("%d",i);
&nb ......

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;
&nbs ......

自动化测试中Python与C/C++的混合使用


背景
项目的
自动化测试中已经使用了基于Python
脚本的框架,自动化过程中最关键的问题就是如何实现桩模块。运用
Python
强大的功能,实现任何桩模块都是可能的,但是是否必须完全使用
Python
实现模块逻辑,成本是一个决定性因素。在桩模块逻辑简单的情况下,使用
Python
模拟模块逻辑不但使自动化测试的结构清 ......

linux C使用管道通信(一)

 Linux中的进程通信
1.管道
   函数原型:int pipe(int filedes[2]);
   函数返回值: 正确返回0;错误返回-1
   其中的文件描述符filedes[0]是用来读取数据的,filedes[1]是用来写数据的。
例子1:
#include<stdio.h>
#include<stdlib.h>
#include<u ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号