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

c分析面向对象的实现技术

面向对象编程和结构化编程几乎在同一时期出现。但是由于早些时候的机器环境不允许,如内存、cpu等。导致面向对象技术没有得到及时的发展,而同时因为结构化程序对硬件要求不是那么强烈,所以及时的发展起来了。
但是虽然如此,更多的人在谈到面向对象时总觉得是种优越,总觉得"高人一等",自认为c++一定比c优秀。下面通过用c来实现对象,也说明它们之间的关系,以及面向对象的本质实现。
在开发用户管理系统的时候,一般的user类都如此,java实现:
public class User {
String name;
String password;

public User(String n, String pwd) {
this.setName(n);
this.setPassword(pwd);
}
public String getName() {
return this.name;
}
public String getPassword() {
return this.password;
}
public void setName(String n) {
this.name = n;
}
public void setPassword(String pwd) {
this.password = pwd;
}
public String toString(){
return "name:" + this.getName() + ",password:" + this.getPassword();
}
public static void main(String[] args) {
User u = new User("abc","456");
System.out.println(u.toString());
}

}  
 
下面通过c的实现展示如何实现面向对象技术: 
 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
* array.c
*
* Created on: 2009-7-20
* Author: cangyingzhijia
*
* c模拟面向对象实现
*/
struct User;
typedef char * String;
static String _toString(struct User *this);
static String _getPassword(struct User *this);
static String _getName(struct User *this);
static void _setName(struct User *this, String n);
static void _setPassword(struct User *this, String pwd);
static void _construct(struct User *this, String n, String pwd);
static void _destruct(struct User *this);
/**
* 定义方法操作表
*/
static struct operation {
void (*construct)(struct User *this, String n, String pwd);
void (*destruct)(struct User *this);
String (*toString)(struct User *this);
String (*getPassword)(struct User *this);
String (*get


相关文档:

DSP C优化2

3.4理解编译器的反馈信息
    在编译C代码时,编译器在产生的.asm文件里向程序员反馈了许多信息,理解这些信息,按它的提示修改C代码,对尽快优化代码很有好处。只要用-k令编译器保留.asm文件,就可读到这些信息。
    对于C优化,重点就是循环,对于反馈信息,我们主要考察编译器对流水线 ......

c 语言可变参数函数例子

#include<stdio.h>
#include<stdarg.h>
#include<string.h>
void demo(char *msg,...)
{
va_list argp;
int arg_number=0;
char *para = msg;
va_start(argp,msg);
while(1){
if ( strcmp( para, "\0") != 0 ) {
arg_number++;
printf("parameter %d is: %s\n",arg_number,p ......

C\C++中全局变量和全局文件的访问作用域

extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字.
它告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用。
1。对于extern变量来说,仅仅是一个变量的声明,其并不是在定义分配内存空间。如果该变量定义多次,会有连接错误
2。通常,在模块的头文件中对本模块提供给其它模块引用的函数和全局 ......

linux 下用C实现‘CAT’的功能

linux
下用C实现‘CAT’的功能
#include<stdio.h>
int main(int argc,char *argv[]){
FILE *file;
char buf[1024],name[20];
int n;
if(argc != 2){
printf("wrong argument\n");
return 1;
}
file=fopen(argv[1],"r");
if(file==NULL){
printf("Cant't open!\n&quo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号