⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 此源码是著名的教材BeginningLinux Programming中文名字叫Linux程序设计书中的源代码
💻 C
字号:
#include<stdio.h>
#include<stdlib.h>

#define FATHER(child) (struct Father *)(child)

void print1(int i)
{
	printf("this is father and i = %d\n",i);
}

void print2(int i)
{
	printf("this is child  and i = %d\n",i);
}

struct Father {
	int  a;
	void (*pointer1_to_function)(int);
};

struct Child {
	struct Father f;
	int b;
	void (*pointer2_to_function)(int);
};

void father_member_funtion(struct Father *f,char *string)
{
	printf("\n");
	f->pointer1_to_function(f->a);
	printf("%s\n\n",string);
}

int main()
{
	struct Child *p_child;
	p_child = (struct Child *)malloc(sizeof(struct Child));
	p_child->f.a = 10;
	p_child->f.pointer1_to_function = print1;
	p_child->b   = 20;
	p_child->pointer2_to_function   = print2;
		
	p_child->pointer2_to_function(p_child->b);
		
	struct Father *p_father = FATHER(p_child);
	p_father->pointer1_to_function(p_father->a);
		
	father_member_funtion(p_father,"hello");
		
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -