相似 nginx 编译时生成函数链表

下面代码可能须要一定的c/c++基础。

须要有一些函数指针的知识

深度剖析函数指针点击这里

common.h

#pragma once
typedef int (*pt)(void);
void init_2();

2.cpp

#include <iostream>
#include "common.h"
using namespace std;
static pt next_pt;
extern pt top_pt;
int filter_2()
{
    cout<<"filter_2"<<endl;
    if(next_pt)
        next_pt();
}
static void filter_2_init()
{
    next_pt = top_pt;
    top_pt = filter_2;
}
void init_2()
{
    filter_2_init();
}

1.cpp

#include <iostream>
#include "common.h"
using namespace std;
static pt next_pt;
pt top_pt;

static int filter_1()
{
    cout<<"filter_1"<<endl;
    if(next_pt)
        next_pt();
}
static void filter_init()
{
    next_pt = top_pt;
    top_pt = filter_1;
}
void init_1()
{
    filter_init();
}
int main()
{
    init_1();
    init_2();
    top_pt();
    return 0;
}

编译命令

g++ 1.cpp 2.cpp -g -O0

运行

./a.out

filter_2

filter_1

假设你已经编程并运行成功,请继续往下看.

top_pt 为全局变量

next_pt为局部全局变量

假设你想知道

top_pt 在每次代码运行时都会变化。不断地指向新的链表头部,通过init_*函数的不断运行,一条链表就产生了。

看起来就像是用全局变量组成了一条单项链表。

好吧。又是奇淫技巧,如是而已。

时间: 2024-08-27 01:04:14

相似 nginx 编译时生成函数链表的相关文章

类似 nginx 编译时生成函数链表

以下代码可能需要一定的c/c++基础. 需要有一些函数指针的知识 深度剖析函数指针点击这里 common.h #pragma once typedef int (*pt)(void); void init_2(); 2.cpp #include <iostream> #include "common.h" using namespace std; static pt next_pt; extern pt top_pt; int filter_2() { cout<&l

nginx 编译的问题

最近在编译安装nginx时遇到个奇怪的问题,翻遍国内外网站都没有得到解决.主要问题是checking时报如下的错: 安装php的时候也是报这个错,但我用手动编译安装openssl后,php编译安装通过. 方法一 ------------------------------------------------------------------------------------------------------------------------------------------------

获取安装后Apache、MySQL、Nginx、PHP编译时参数

# cat /usr/local/apache2/build/config.nice      //获取Apache编译时的参数 #!/bin/sh # #Created by configure "./configure"\ "--enable-modules=all"\ "--enable-mods-shared=all"\ "--enable-charset-lite"\ "--enable-unique-id

nginx增加ssl支持 - 编译时参数详情列表

./configure \ --with-http_ssl_module \ make && make install nginx编译参数说明如下: --prefix=<path> -- 安装路径,如果没有指定,默认为/usr/local/nginx.--sbin-path=<path> -- nginx可执行命令的文件,如果没有指定,默认为<prefix>/sbin/nginx.--conf-path=<path> -- 在没有使用-c参数

查看已安装的 apache、nginx、php、mysql 编译时参数

新接手一台机器,不太确定编译时都启用了哪些选项,特此整理一下: 查看 nginx 编译参数:/usr/local/nginx/sbin/nginx -V 查看 apache 编译参数:cat /usr/locla/apache2/build/config.nice 查看 mysql 编译参数:cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE_LINE 查看 php 编译参数:/usr/local/php/bin/php -i | grep co

Nginx编译安装,启动,停止,升级。

1.简单介绍下Nginx Nginx是一款轻量级的web服务器和反向代理服务器,它使用了epoll的I/O模型,也就是事件触发I/O模型,减少了进程的生成切换所消耗的系统资源(CPU的压力减少,内存的占用也会减少),可以达到很高的并发请求.它是一款开源软件,企业成本降低,它的使用配置也比较简单,同时支持Rewrite,作为反向代理的时候可以检查后端的Web服务器的健康状况,能够支持热部署. 2.Nginx安装,重启,升级,停止. 环境是Centos系统,通过www.nginx.org下载需要的源

NGINX编译安装后添加新模块的方法

刚忙完研发又有新的需求过来,测试服务器的nginx需要有HttpUpstreamRequestHashModule和HttpStubStatusModule:擦!安装软件环境时怎么不说清楚:妹的,悲剧. 测试服务器崩溃的是不是我安装的软件,天啊.赶紧搞吧!!! 环境:centos 6.4 64位 编译安装nginx 1:查看nginx版本和安装时间带的具体参数  /usr/local/nginx/sbin/nginx  -V 2:下载相应的版本的nginx源码包[nginx-1.5.11.tar

Linux下nginx编译安装教程和编译参数详解

这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # yum install pcre* //如过你已经装了,请跳过这一步 2.安装openssl 需要ssl的支持,如果不需要ssl支持,请跳过这一步 复制代码代码如下: # yum install openssl* 3.gzip 类库安装 复制代码代码如下: yum install zlib zlib-

nginx编译安装参数

nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-path= 指向配置文件(nginx.conf) --error-log-path= 指向错误日志目录 --pid-path= 指向pid文件(nginx.pid) --lock-path= 指向lock文件(nginx.lock)(安装文件锁定,防止安装文件被别人利用,或自己误操作.) --user= 指定程序运行时的非特权用户 --group= 指定程序运行时的非特权