Similar Nginx compile-time generated function chain list

Source: Internet
Author: User
The following code may require a certain C + + base.

Need some knowledge of function pointers

Depth profiling function pointer click here

Common.h

#pragma oncetypedef int (*pt) (void); void init_2 ();

2.cpp
#include
 
  #include "Common.h" using namespace std;static pt Next_pt;extern pt Top_pt;int filter_2 () {cout<< ' filter_2 ' <
  
   1.cpp
   
 #include 
     
       #include "common.h" using namespace std;static pt next_pt;pt top_pt;static int fil Ter_1 () {cout<< "filter_1" < 
      
        compile command 
       

g++ 1.cpp 2.cpp-g-o0

Execute

./a.out

Filter_2
filter_1
If you've programmed and executed successfully , please continue looking down.

Top_pt is a global variable

Next_pt is a local global variable

If you want to know

The

Top_pt will change every time the code executes, pointing to the new list header, and a linked list is generated by the continuous execution of the init_* function. It looks like a single list with global variables.

Well, it's the trick, too!

Above introduces similar Nginx compile-time generated function chain list, including the contents of the content, I hope that the ph P Tutorials Interested friends are helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.