How to print function pointers with cout?

前端 未结 7 2557
挽巷
挽巷 2020-11-22 07:09

I want to print out a function pointer using cout, and found it did not work. But it worked after I converting the function pointer to (void *), so does printf with %p, such

7条回答
  •  离开以前
    2020-11-22 07:21

    maybe (in one time I stay intersecting about the address of function) one of decision )))

    #include      
    #include 
    
    void alexf();
    
    int main()
    { 
        int int_output;
    
        printf("printf(\"%%p\", pf) is %p\n", alexf);
    
        asm( "movl %[input], %%eax\n"                
             "movl %%eax, %[output]\n" 
             : [output] "+m" (int_output)
             : [input] "r" (&alexf)
             : "eax", "ebx"
        );
    
            std::cout<<"" <

    passing the pointer to function (&alexf) or other pointer using & use constraint r. Let gcc to use register for input argument)).

提交回复
热议问题