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
相关文档:
一、获取日历时间
time_t是定义在time.h中的一个类型,表示一个日历时间,也就是从1970年1月1日0时0分0秒到此时的秒数,原型是:
typedef long time_t; /* time value */
可以看出time_t其实是一个长整型,由于长整型能表示的数值有限,因此它能表示的最迟时间是2038年 ......
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 ......
使用 C# 2.0 命令行编译器
http://msdn.microsoft.com/zh-cn/library/ms379563(vs.80).aspx#mainSection
摘要:本文分析了使用 C# 命令行编译器 csc.exe 生成应用程序的过程。同时,还将向读者介绍很多为 C# 2.0 独有的编译器选项,例如,extended/reference 标志和强名称支持。阅读完本文的内容之后,您将能够轻松地在没 ......
命令行界面的程序,通常都需要输入命令行参数帮助程序执行。main是最典型的此类应用,main的参数之前都被忽略掉了。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int count;
printf("The command line has %d arguments:\n", ......
Linux中的进程通信
1.管道
函数原型:int pipe(int filedes[2]);
函数返回值: 正确返回0;错误返回-1
其中的文件描述符filedes[0]是用来读取数据的,filedes[1]是用来写数据的。
例子1:
#include<stdio.h>
#include<stdlib.h>
#include<u ......