Home Backend Development PHP Tutorial Similar to nginx, a function linked list is generated when compiling

Similar to nginx, a function linked list is generated when compiling

Aug 08, 2016 am 09:22 AM
filter next quot

The following code may require a certain c/c++ foundation.

You need to have some knowledge of function pointers

Click here for in-depth analysis of function pointers

common.h

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

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();
}
Copy after login
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;
}
Copy after login
compilation command

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

Execute

./a.out

filter_2
filter_1
If you have already programmed and executed successfully, please continue reading.

top_pt is a global variable

next_pt is a local global variable

If you want to know

top_pt will change every time the code is executed, constantly pointing to the head of the new linked list. Through the continuous execution of the init_* function, a linked list is generated. It looks like a single-linked list composed of global variables.

Okay, it’s another weird and obscene technique, that’s all!

The above has introduced the function linked list generated by nginx during compilation, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the '[Vue warn]: Failed to resolve filter' error How to solve the '[Vue warn]: Failed to resolve filter' error Aug 19, 2023 pm 03:33 PM

Methods to solve the "[Vuewarn]:Failedtoresolvefilter" error During the development process using Vue, we sometimes encounter an error message: "[Vuewarn]:Failedtoresolvefilter". This error message usually occurs when we use an undefined filter in the template. This article explains how to resolve this error and gives corresponding code examples. When we are in Vue

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

What is the principle and registration method of filter in Springboot What is the principle and registration method of filter in Springboot May 11, 2023 pm 08:28 PM

1. Filter First look at the location of the filter of the web server. Filter is a chain connected before and after. After the previous processing is completed, it is passed to the next filter for processing. 1.1Filter interface definition publicinterfaceFilter{//Initialization method, only executed once in the entire life cycle. //Filtering services cannot be provided until the init method is successfully executed (failure such as throwing an exception, etc.). //The parameter FilterConfig is used to obtain the initialization parameter publicvoidinit(FilterConfigfilterConfig)throwsServletException;//

How to integrate Filter in SpringBoot2 How to integrate Filter in SpringBoot2 May 16, 2023 pm 02:46 PM

First define a Filter for unified access URL interception. The code is as follows: publicclassUrlFilterimplementsFilter{privateLoggerlog=LoggerFactory.getLogger(UrlFilter.class);@OverridepublicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)throwsIOException,ServletException{H

How to filter in java How to filter in java Apr 18, 2023 pm 11:04 PM

Note 1. If the Lambda parameter generates a true value, the filter (Lambda that can generate a boolean result) will generate an element; 2. When false is generated, this element will no longer be used. Example to create a List collection: ListstringCollection=newArrayList();stringCollection.add("ddd2");stringCollection.add("aaa2");stringCollection.add("bbb1");stringC

CSS visual property analysis: box-shadow, text-shadow and filter CSS visual property analysis: box-shadow, text-shadow and filter Oct 20, 2023 pm 12:51 PM

Analysis of CSS visual properties: box-shadow, text-shadow and filter Introduction: In web design and development, CSS can be used to add various visual effects to elements. This article will focus on the three important properties of box-shadow, text-shadow and filter in CSS, including their usage and effect display. Below we analyze these three properties in detail. 1. box-shadow (box shadow) box-shado

Detailed explanation of CSS blur properties: filter and backdrop-filter Detailed explanation of CSS blur properties: filter and backdrop-filter Oct 20, 2023 pm 04:48 PM

Detailed explanation of CSS fuzzy attributes: filter and background-filter Introduction: When designing web pages, we often need some special effects to increase the visual appeal of the page. The blur effect is one of the common special effects. CSS provides two blur attributes: filter and background-filter, which are used to blur element content and background content respectively. This article explains these two properties in detail and provides some concrete code examples. 1. filter

Optional class in Java 8: How to filter possibly null values ​​using filter() method Optional class in Java 8: How to filter possibly null values ​​using filter() method Aug 01, 2023 pm 05:27 PM

Optional class in Java8: How to use the filter() method to filter possibly null values ​​In Java8, the Optional class is a very useful tool that allows us to better handle possibly null values ​​and avoid the occurrence of NullPointerException. The Optional class provides many methods to manipulate potential null values, one of the important methods is filter(). The function of the filter() method is that if Option

See all articles